Very simple - python


  • 0
    S
    class Solution(object):
        def findContestMatch(self, n):
            """
            :type n: int
            :rtype: str
            """        
            
            current = collections.deque([ str(i) for i in range(1, n+1) ])
            next_round = collections.deque([])
            swap_ref   = None
            while len(current) > 1:
                while current:
                    strong     = current.popleft()
                    weak       = current.pop()
                    play       = '(' + strong + ',' + weak + ')'
                    next_round.append(play)
                swap_ref = current
                current  = next_round
                next_round = swap_ref
            return current[0]

Log in to reply
 

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