9 lines python


  • 0
    B
    class Solution(object):
        def findContestMatch(self, n):
            """
            :type n: int
            :rtype: str
            """
            alist = [str(i+1) for i in range(n)]
            while True:
                if len(alist) <= 2: break
                tmp, left, right = [], 0, len(alist)-1
                while left < right:
                    tmp.append( '(' + alist[left] + ',' + alist[right] + ')' )
                    left, right = left+1, right-1
                alist = tmp
            return '(' +  ",".join(alist) + ')'
    

Log in to reply
 

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