题目描述
方法:
创建numRow行数组保存z字
class Solution:
def convert(self, s: str, numRows: int) -> str:
if numRows==1 or not s:
return s
n = len(s)
record = [[] for i in range(numRows)]
i,j = 0,-1
flag = 1
while i < n:
if flag and j < numRows-1:
j += 1
elif flag and j == numRows-1:
flag = 0
if not flag and j>0:
j -= 1
elif not flag and j == 0:
j += 1
flag = 1
record[j].append(s[i])
i += 1
res = []
for line in record:
res += line
return "".join(res)