python;leetcode Z字型变换

class Solution(object):
    def convert(self, s, numRows):
        """
        :type s: str
        :type numRows: int
        :rtype: str
        """
        if numRows == 1 or numRows >= len(s):
            return s

        L = [''] * numRows #建立长度为num的空列表
        index, step = 0, 1

        for x in s:
            L[index] += x
            if index == 0:
                step = 1
            elif index == numRows -1:
                step = -1
            index += step  # 来回对l进行添加字符

        return ''.join(L)

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