One-line Python solution (accepted)


  • 0

    One-liner just for fun:

    class Solution(object):
        def convert(self, s, numRows):
            """
            :type s: str
            :type numRows: int
            :rtype: str
            """
            return ''.join([i[1] for i in sorted({((numRows-1)-abs((numRows-1)-i%(2*(numRows-1))),i):c for i,c in enumerate(s)}.viewitems())]) if numRows > 1 else s
    

Log in to reply
 

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