recursion with python


  • 0
    class Solution(object):
        def findContestMatch(self, n):
            """
            :type n: int
            :rtype: str
            """
            teams = [str(i) for i in range(1, n + 1)]
            
            def round(teams):
                if len(teams) > 1:
                    fight = []
                    low = 0
                    high = len(teams) - 1
                    while high > low:
                        fight.append("(" + teams[low] + "," + teams[high] + ")")
                        low += 1
                        high -= 1
                    return round(fight)
                else:
                    return teams
            
            return round(teams)[0]
    

Log in to reply
 

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