[LeetCode]6. ZigZag Conversion
6. ZigZag Conversion
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
        level = [''] * numRows
        index, step = 0, 1
        for i in range(len(s)):
            level[index] += s[i]
            if index == 0:
                step = 1
            elif index == numRows - 1:
                step = -1
            index += step
        return ''.join(level) 
关注公众号:数据结构与算法那些事儿,每天一篇数据结构与算法
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号