Two-line python (~105ms, 82%)


  • 1
    H

    The idea is to sort the string according to row index and its original position

    class Solution(object):
        def convert(self, s, numRows):
            i=(range(numRows)+range(numRows-2,0,-1))*(len(s)/numRows+1)
            return ''.join([x for (_,_,x) in sorted(zip(i,range(len(s)),s))])
    

Log in to reply
 

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