深刻感受到,代码很多的一下子很难看懂,写一写就瞬间理解。。
还有现在还是菜啊,还得总是去看题解。。。说起题解。。。我居然一段时间都是在评论里面翻答案。。应该是去题解里面直接找的。。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21class Solution: def convert(self, s: str, numRows: int) -> str: length=len(s) new_s=[""] * numRows #if length==0 : # return "" if numRows==1 : return s else : i=0 while i<length: for j in range(numRows): if i<length: new_s[j]+=s[i] i+=1 for j in range(numRows-2,0,-1): if i<length: new_s[j]+=s[i] i+=1 return "".join(new_s)
join()函数对于这个地方来说真是太方便了啊,
每次总是感叹人家算法的精妙
最后
以上就是坦率奇迹最近收集整理的关于python刷题之Z字形变换(其实是N字形好吧)的全部内容,更多相关python刷题之Z字形变换(其实是N字形好吧)内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复