Clean python code


  • 1
    G

    Ok, it is basically a math problem. Here is my code:
    '''

    def convert(self, s, numRows):
        if numRows==1: return s
        rows=[[] for i in range(numRows)]
        k=2*numRows-2
        for i,ch in enumerate(s):
            r=min(i%k,k-i%k)
            rows[r].append(ch)
        str=''
        for row in rows:
            str+=''.join(row)
        return str

Log in to reply
 

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