Skip to content

Commit f7f7d0c

Browse files
Create 6. ZigZag Conversion.py
1 parent 17cc447 commit f7f7d0c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

6. ZigZag Conversion.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution:
2+
# @param {string} s
3+
# @param {integer} numRows
4+
# @return {string}
5+
def convert(self, s, numRows):
6+
7+
if numRows == 1:
8+
return s
9+
10+
rows = ["" for i in range(numRows)]
11+
12+
direction = -1
13+
row = 0
14+
for i in range(len(s)):
15+
16+
rows[row]+=s[i]
17+
if (row == 0 or row==numRows-1):
18+
direction *= -1
19+
row+=direction
20+
21+
return "".join(rows)
22+

0 commit comments

Comments
 (0)