【leetcode❤python】 6. ZigZag Conversion

#-*- 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)       

posted @ 2016-11-13 19:27  火金队长  阅读(266)  评论(0编辑  收藏  举报