Leetcode 1688. Count of Matches in Tournament

2021-08-13 11:54:51 浏览数 (1)

1. Description

2. Solution

**解析:**Version 1,按讲述的规则实现即可,最后其实会发现结果始终是n-1

  • Version 1
代码语言:javascript复制
class Solution:
    def numberOfMatches(self, n: int) -> int:
        total = 0
        while n != 1:
            matches = n // 2
            total  = matches
            if n % 2 == 0:
                n = matches
            else:
                n = matches   1
        return total
        # return n - 1

Reference

  1. https://leetcode.com/problems/count-of-matches-in-tournament/

0 人点赞