-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ6.py
More file actions
30 lines (25 loc) · 704 Bytes
/
Q6.py
File metadata and controls
30 lines (25 loc) · 704 Bytes
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
27
28
29
30
class Solution(object):
def convert(self, s, numRows):
"""
:type s: str
:type numRows: int
:rtype: str
"""
size = len(s)
if numRows ==1:
return s
goDown = False
cur_row = 0
rows = min(numRows,size)
res = [""]*rows
for i in range(size):
res[cur_row]+=s[i]
if cur_row==0 or cur_row==(rows-1):
goDown = not goDown
cur_row+= 1 if goDown else-1
resString = ""
for j in res:
resString+=j
return resString
if __name__ == '__main__':
Solution().convert("PAYPALISHIRING",3)