Skip to content

Add soulution.go for 0006.ZigZag Conversion #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add soulution.go for 0007.Reverse Integer
  • Loading branch information
Yeqi Tao committed Jun 30, 2019
commit dc72d258c29a769e6177435be0c710cf10142e2b
23 changes: 23 additions & 0 deletions solution/0007.Reverse Integer/Solution.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
func reverse(x int) int {
slot := make([]int, 11)
count := 0
for x != 0 {
n := x%10
slot[count] = n
count++
x /= 10
}
result := 0
flag := true
for i := 0; i < count; i++ {
if flag && slot[i] == 0 {
continue
}
flag = false
result = 10 * result + slot[i]
}
if result > math.MaxInt32 || result < math.MinInt32 {
return 0
}
return result
}
1 change: 1 addition & 0 deletions solution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
├── 0007.Reverse Integer
│   ├── README.md
│   ├── Solution.java
│   ├── Solution.go
│   ├── Solution.js
│   ├── Solution.py
│   ├── Solution.rb
Expand Down