My python solution for ZigZag Conversion


  • 0
    L

    It's not short but I think it's logic is more clear.

    class Solution(object):
        def convert(self, s, numRows):
            if numRows==1:
                return s
            else:
                n=numRows-1
                str=['' for i in range(0, numRows)]
                for i in range(0, len(s)):
                    if (i//n)%2==0:
                        str[i%n]+=s[i]
                    elif (i//n)%2==1:
                        str[n-i%n]+=s[i]
                string=''
                for i in range(0, numRows):
                    string=string+str[i]
                return string

Log in to reply
 

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