Simple python solution


  • 0
    Y
    class Solution(object):
        def convert(self, s, numRows):
            """
            :type s: str
            :type numRows: int
            :rtype: str
            """
            idx = 0
            res = ['' for _ in xrange(numRows)]
            group = 2 * numRows - 2
            while idx<=len(s)-1:
                for i in xrange(0, numRows):
                    if idx>=len(s): break
                    res[i] += s[idx]
                    idx += 1
                start = -2
                for i in xrange(numRows, group):
                    if idx>=len(s): break
                    res[start] += s[idx]
                    idx += 1
                    start -= 1
            final = ''
            for i in xrange(len(res)):
                final += res[i]
            return final
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.