LeetCode 6 z字型变换

class Solution:
    def convert(self, s, numRows):
        l = len(s)
        if numRows == 1:
            return s
        if l <= 1:
            return s
        res = [''for i in range(l)]
        step, row = 1, 0
        for i in s:
            if row == 0:
                step = 1
            if row == numRows - 1:
                step = -1
            res[row] += i
            row += step
        return ''.join(res)

《LeetCode 6 z字型变换》

 

把每一行当做一个list的元素,然后在每个元素中不断的插入数据。

借鉴于https://www.cnblogs.com/mzct123/p/5914383.html

    原文作者:Z字形编排问题
    原文地址: https://blog.csdn.net/qq_39416129/article/details/82997305
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞