def convert(s: str, numRows: int) -> str:
strList = []
length = len(s)
if numRows > 2:
interNum = numRows - 2
for i in range(0, length, numRows + interNum):
strList.append(s[i])
for n in range(1, numRows - 1):
for i in range(n, length, numRows + interNum):
strList.append(s[i])
if i + numRows + interNum - 2 * n < length:
strList.append(s[i + numRows + interNum - 2 * n])
for i in range(numRows - 1, length, numRows + interNum):
strList.append(s[i])
else:
for n in range(numRows):
for i in range(n, length, numRows):
strList.append(s[i])
return ''.join(strList)
Z字形变换
最新推荐文章于 2024-06-18 11:34:30 发布