LeetCode 6. Z 字形变换
题目描述
思路分析
方法一:按行排序
方法二:模拟
参考代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
func convert(s string, numRows int) string {
if numRows == 1 {
return s
}
rows := make([]string, numRows)
down := true
curRow := 0
for _, c := range s {
rows[curRow] += string(c)
if curRow == 0 {
down = true
} else if curRow == numRows-1 {
down = false
}
if down {
curRow++
} else {
curRow--
}
}
res := ""
for _, row := range rows {
res += row
}
return res
}
1
write your code here
CC BY-NC-SA 4.0
许可协议,转载请注明出处!
本博客所有文章除特别声明外,均采用