-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathZigZag-Conversion.py
More file actions
30 lines (29 loc) · 888 Bytes
/
ZigZag-Conversion.py
File metadata and controls
30 lines (29 loc) · 888 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):
finalZig = [[] for i in range(numRows)]
s = list(s)
o = ''
y = 0
while (len(s) > 0):
y += 1
print y
for i in range(numRows):
try:
finalZig[i].append(s.pop(0))
except Exception as exp:
break
index = (numRows - 2)
while (index > 0):
for i in range(numRows):
if (i != index):
finalZig[i].append('')
else:
try:
finalZig[i].append(s.pop(0))
except:
break
index = (index - 1)
o = ''
for v in finalZig:
o += ''.join(v)
return o