Login dark
class Solution:
    def convert(self, s: str, numRows: int) -> str:
        if numRows == 1:
            return s
        li = [''] * numRows
        #当前行数
        lineNum = 1
        #是否自上至下
        up2down = True
        for i in range(len(s)):
            li[lineNum-1] += s[i]
            if up2down:
                #从上到下
                if lineNum != numRows:
                    lineNum += 1
                else:
                    lineNum -= 1
                    up2down = False
            else:
                #从下到上
                if lineNum != 1:
                    lineNum -= 1
                else:
                    lineNum += 1
                    up2down = True
        return ''.join(li)

作者:moozik
链接:https://leetcode-cn.com/problems/zigzag-conversion/solution/zui-ben-de-fang-fa-shun-xu-bian-li-by-moozik/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。