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字形变换
字符串转换算法
最新推荐文章于 2025-05-23 17:46:09 发布
1128

被折叠的 条评论
为什么被折叠?



