Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion 1-100q/06.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,23 @@ def convert(self, s, numRows):
final_string += value
return final_string

print Solution().convert("PAYPALISHIRING",3)
print Solution().convert("PAYPALISHIRING",3)


'''
Alternative Solution
'''

class Solution:
def convert(self, s: str, numRows: int) -> str:
if numRows == 1: return s
out = [[] for _ in range(numRows)]
goingDown = False
nextt = 0
for char in s:
out[nextt].append(char)
if nextt == 0 or nextt == numRows - 1:
goingDown = not goingDown
if not goingDown: nextt += 1
else: nextt -= 1
return ''.join(["".join(arr) for arr in out])