时间复杂度: O(n)
空间复杂度: O(n)
class Solution:
def convert(self, s: str, numRows: int) -> str:
if numRows==1:
return s
out=""
for index in range(numRows):
step=2 *(numRows-1 -index)
while index <len(s):
if step!=0 or index<numRows:
out+=s[index]
if index>numRows-2:
step = 2 * (numRows - 1) - step
index += step
return out
自己找规律写的,发现代码一段时间不写,写的就很慢很慢了。过了leetcode,但通义千问硬说我错了。
各位网友们怎么看
1892

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



