Neat simple python solution

  • 0
    class Solution(object):
        def findContestMatch(self, n):
            resultArr = self.recursivelyArrange([str(i) for i in range(1, n+1)])
            return ",".join(resultArr)
        def recursivelyArrange(self, arr):
            result = []
            for i in range(len(arr)/2):
                result.append("("+ arr[i] + "," + arr[-i-1] + ")")
            if len(result) == 1:
                return result
                return self.recursivelyArrange(result)

Log in to reply

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