File tree Expand file tree Collapse file tree 4 files changed +83
-0
lines changed
0008.String to Integer (atoi) Expand file tree Collapse file tree 4 files changed +83
-0
lines changed Original file line number Diff line number Diff line change
1
+ func convert (s string , numRows int ) string {
2
+ if numRows == 1 {
3
+ return s
4
+ }
5
+ length := len (s )
6
+ result := make ([]byte , length )
7
+ step := 2 * numRows - 2
8
+ count := 0
9
+ for i := 0 ; i < numRows ; i ++ {
10
+ for j := 0 ; j + i < length ; j += step {
11
+ result [count ] = s [i + j ]
12
+ count ++
13
+ if i != 0 && i != numRows - 1 && j + step - i < length {
14
+ result [count ] = s [j + step - i ]
15
+ count ++
16
+ }
17
+ }
18
+ }
19
+ return string (result )
20
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ func myAtoi (str string ) int {
2
+ cer := 0
3
+ result := 0
4
+ tmpResult := 0
5
+ flag := false
6
+ for _ , n := range str {
7
+ if ! flag && n == ' ' {
8
+ continue
9
+ }
10
+ flag = true
11
+ if cer == 0 {
12
+ if n >= '0' && n <= '9' {
13
+ cer = 1
14
+ } else if n == '+' {
15
+ cer = 1
16
+ continue
17
+ } else if cer == 0 && (n == '-' ) {
18
+ cer = - 1
19
+ continue
20
+ }
21
+ }
22
+
23
+ if n >= '0' && n <= '9' {
24
+ tmpResult = tmpResult * 10 + ((int )(n ) - 48 )
25
+ result = cer * tmpResult
26
+ } else {
27
+ break
28
+ }
29
+ if result < math .MinInt32 {
30
+ return math .MinInt32
31
+ }
32
+ if result > math .MaxInt32 {
33
+ return math .MaxInt32
34
+ }
35
+ }
36
+ return result
37
+ }
Original file line number Diff line number Diff line change 41
41
โย ย โโโ README.md
42
42
โย ย โโโ Solution.cpp
43
43
โย ย โโโ Solution.java
44
+ โย ย โโโ Solution.go
44
45
โย ย โโโ Solution.js
45
46
โย ย โโโ Solution.py
46
47
โโโ 0007.Reverse Integer
47
48
โย ย โโโ README.md
48
49
โย ย โโโ Solution.java
50
+ โย ย โโโ Solution.go
49
51
โย ย โโโ Solution.js
50
52
โย ย โโโ Solution.py
51
53
โย ย โโโ Solution.rb
52
54
โย ย โโโ Solution2.py
53
55
โโโ 0008.String to Integer (atoi)
54
56
โย ย โโโ Solution.java
57
+ โย ย โโโ Solution.go
55
58
โย ย โโโ Solution.js
56
59
โย ย โโโ Solution.py
57
60
โโโ 0009.Palindrome Number
You canโt perform that action at this time.
0 commit comments