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 7e2e39b commit 857dc09Copy full SHA for 857dc09
solution/0006.ZigZag Conversion/Solution.go
@@ -0,0 +1,20 @@
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
16
17
18
19
+ return string(result)
20
+}
solution/README.md
@@ -41,6 +41,7 @@
41
│ ├── README.md
42
│ ├── Solution.cpp
43
│ ├── Solution.java
44
+│ ├── Solution.go
45
│ ├── Solution.js
46
│ └── Solution.py
47
├── 0007.Reverse Integer
0 commit comments