We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 857dc09 commit dc72d25Copy full SHA for dc72d25
solution/0007.Reverse Integer/Solution.go
@@ -0,0 +1,23 @@
1
+func reverse(x int) int {
2
+ slot := make([]int, 11)
3
+ count := 0
4
+ for x != 0 {
5
+ n := x%10
6
+ slot[count] = n
7
+ count++
8
+ x /= 10
9
+ }
10
+ result := 0
11
+ flag := true
12
+ for i := 0; i < count; i++ {
13
+ if flag && slot[i] == 0 {
14
+ continue
15
16
+ flag = false
17
+ result = 10 * result + slot[i]
18
19
+ if result > math.MaxInt32 || result < math.MinInt32 {
20
+ return 0
21
22
+ return result
23
+}
solution/README.md
@@ -47,6 +47,7 @@
47
├── 0007.Reverse Integer
48
│ ├── README.md
49
│ ├── Solution.java
50
+│ ├── Solution.go
51
│ ├── Solution.js
52
│ ├── Solution.py
53
│ ├── Solution.rb
0 commit comments