- ignore mathmatic things and just use rows to record strings
- turn around when index get to the border
Complexity T : O(n) M : O(n)
class Solution:
def convert(self, s, numRows):
"""
:type s: str
:type numRows: int
:rtype: str
"""
if numRows == 1 or numRows > len(s):
return s
rows = [''] * numRows
index, step = 0, 1
for x in s:
rows[index] += x
if index == 0:
step = 1
elif index == numRows - 1:
step = -1
index += step
return ''.join(rows)