leetcode:6. Z 字形变换

leetcode:6. Z 字形变换
思路:
简单模拟,注意特殊情况numsrow = 1

src:

class Solution:
    def convert(self, s: str, numRows: int) -> str:
        len1 = len(s)
        cnt = 0
        i = 0
        flag = "down"
        lists = [[] for i in range(numRows)]#二维数组的建立
        while cnt < len1:
            lists[i].append(s[cnt])
            cnt += 1
            #特殊的处理
            if numRows == 1:
                continue
            if i == 0:
                flag = "down"
            if i == numRows - 1:
                flag = "up"
            if flag == "down":
                i += 1
            else:
                i -= 1
        res = ""
        for i in range(numRows):
            res += "".join(lists[i])
        return res

总结:
简单模拟即可

上一篇:windows--OSError: [Errno 22] Invalid argument: '\u202aE:/desk/Desktop/test.txt' 读取文件的坑


下一篇:virtualenv在windows上打开