Skip to content

Commit 8f780a4

Browse files
authored
zig Zag conversion.py
1 parent 5bebaf9 commit 8f780a4

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

ZigZag Conversion

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def convert(self, s: str, numRows: int) -> str:
3+
if numRows==1:return s
4+
5+
res=""
6+
for r in range(numRows):
7+
increment=2*(numRows-1)
8+
for i in range(r,len(s),increment):
9+
res+=s[i]
10+
if(r>0 and r<numRows-1 and i + increment-2*r<len(s)):
11+
res+=s[i+increment-2*r]
12+
13+
return res

0 commit comments

Comments
 (0)