Python solution

  • 0

    I think it's rather easy to understand that a few others:

    class Solution:
        # @return a string
        def convert(self, s, nRows):
            if nRows <= 1: return s
            ret = []
            r = nRows - 1
            for i in range(nRows):
                for c in range(len(s)/r/2+1):
                    c1 = 2*c*r+i
                    c2 = (2*c+2)*r-i
                    if c1 < len(s):
                    if c1 != c2 and i != 0 and c2 < len(s):
            return ''.join(ret)

Log in to reply

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