forked from JediXL/LeetCodeByPython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path06ZigZag.py
38 lines (34 loc) · 791 Bytes
/
06ZigZag.py
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
31
32
33
34
35
36
37
38
class Solution:
def convert(self, s, numRows):
"""
:type s: str
:type numRows: int
:rtype: str
"""
if numRows == 1:
return(s)
zlist = []
sc = ""
n = numRows
while n:
zlist.append([])
n = n - 1
j = 0
for a in s:
if j == 0:
coverse = False
zlist[j].append(a)
if j + 1 < numRows:
if coverse:
j = j - 1
else:
j = j + 1
else:
j = j - 1
coverse = True
for z in zlist:
for t in z:
sc = sc + t
return(sc)
s = Solution()
print(s.convert('ABC', 1))