Skip to content

Latest commit

 

History

History
21 lines (19 loc) · 456 Bytes

1688.md

File metadata and controls

21 lines (19 loc) · 456 Bytes

1688. Count of Matches in Tournament

Solution 1 (time O(n), space O(1))

class Solution(object):
    def numberOfMatches(self, n):
        """
        :type n: int
        :rtype: int
        """
        ans = 0
        while n > 1:
            if n % 2 == 0:
                ans += n // 2
                n = n // 2
            else:
                ans += n // 2
                n = n // 2 + 1
        return ans