-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path006_zigzag.py
More file actions
26 lines (18 loc) · 754 Bytes
/
Copy path006_zigzag.py
File metadata and controls
26 lines (18 loc) · 754 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
class Solution:
def convert(self, s: str, numRows: int) -> str:
res = ''
l = 2 * numRows - 2
if l == 0:
return s
for i in range (0, numRows):
temp = i
while (i < len(s)):
res = res + s[i]
if (i % l) != 0 and (i % l) != (numRows - 1):
if i + (numRows - temp - 1) * 2 < len(s):
res = res + s[i + (numRows - temp - 1) * 2]
i = i + l
return res
print(Solution().convert(s = "A", numRows = 1))
#print(Solution().convert(s = "PAYPALISHIRING", numRows = 3)) #PAHNAPLSIIGYIR
#print(Solution().convert(s = "PAYPALISHIRING", numRows = 4)) #PINALSIGYAHRPI