【leetcode❤python】 6. ZigZag Conversion

时间:2022-07-04 12:15:38

#-*- coding: UTF-8 -*-
#ZigZag Conversion :之字型
class Solution(object):
    def convert(self, s, numRows):
        """
        :type s: str
        :type numRows: int
        :rtype: str
        """
        if numRows==1:return s
        row=0
        step=1
        zigzag=['' for i in range(numRows)]
        for c in s:
            if row==0:step=1
            if row==numRows-1:
                step=-1
            zigzag[row]+=c
            row+=step
        return "".join(zigzag)
sol=Solution()
print sol.convert("ABC", 2)