class Solution(object):
def convert(self, s, numRows):
"""
:type s: str
:type numRows: int
:rtype: str
"""
if numRows == 1 or numRows >= len(s):
return s
L = [''] * numRows #建立长度为num的空列表
index, step = 0, 1
for x in s:
L[index] += x
if index == 0:
step = 1
elif index == numRows -1:
step = -1
index += step # 来回对l进行添加字符
return ''.join(L)
python;leetcode Z字型变换
最新推荐文章于 2022-03-01 23:10:28 发布