Skip to content

Commit 5d984f7

Browse files
committed
Create 0006-Solution.py
1 parent 653c04a commit 5d984f7

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution:
2+
def convert(self, s, numRows):
3+
"""
4+
:type s: str
5+
:type numRows: int
6+
:rtype: str
7+
"""
8+
9+
if numRows == 0:
10+
return ""
11+
elif numRows == 1:
12+
return s
13+
14+
Ret = [[] for i in range(numRows)]
15+
i = 0
16+
while i < len(s):
17+
j = 0
18+
while i<len(s) and j<numRows: # Vertical lines
19+
Ret[j].append(s[i])
20+
i+=1
21+
j+=1
22+
j -= 2
23+
while i<len(s) and j>0: # Diagonal lines
24+
Ret[j].append(s[i])
25+
j-=1
26+
i+=1
27+
28+
return "".join(["".join(row) for row in Ret])
29+

0 commit comments

Comments
 (0)