Z字形变换(6)

class Solution:
    def convert(self, s: str, numRows: int) -> str:
        if numRows < 2: return s
        res = ["" for _ in range(numRows)]
        i, flag = 0, -1
        for c in s:
            res[i] += c
            if i == 0 or i == numRows - 1: flag = -flag
            i += flag
        return "".join(res)

 

posted on 2020-08-13 11:21  不要挡着我晒太阳  阅读(94)  评论(0编辑  收藏  举报

导航