Skip to content

Commit 6e23b02

Browse files
Create 6. Zigzag Conversion
1 parent 9992f40 commit 6e23b02

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

6. Zigzag Conversion

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
def convert(self, s, r):
2+
if r==1:
3+
return s
4+
list1=[[] for i in range(r)]
5+
c=0
6+
w=1
7+
ans=""
8+
for i in s:
9+
10+
list1[c].append(i)
11+
if w==1:
12+
c+=1
13+
else:
14+
c-=1
15+
if c==r:
16+
w=w*-1
17+
c=r-2
18+
elif c==-1:
19+
w=w*-1
20+
c=c+2
21+
for i in list1:
22+
ans+="".join(i)
23+
return ans

0 commit comments

Comments
 (0)