Z字形变换
描述
class Solution(object):
def convert(self, s, numRows):
if numRows == 1:
return s
restr = ""
line = min(len(s), numRows)
chars = ["" for i in range(line)]
change = False # 判断是否到了顶端和底端
j = 0 # 控制list
for i in range(len(s)):
if j % (numRows - 1) == 0:
change = not change
chars[j] += s[i]
j += 1 if change else -1
for i in chars:
restr += i
return restr