Simple Python Solution


  • 0
    S
    import collections
    class Solution:
    # @param {string} s
    # @param {integer} numRows
    # @return {string}
    def convert(self, s, numRows):
        buckets = collections.defaultdict(str)
    	j = 0
    	increment = 1
    	for i , char in enumerate(s):
    		buckets[j] += char
    		j  += increment
    		if j == numRows - 1 or j == 0:
    			increment = - increment
    	keys = list(buckets.iterkeys())
    	keys.sort()
    	return ''.join(buckets[i] for i in keys)
    

    The defaultdict is a bit overkill but I'm lazy


Log in to reply
 

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