美文网首页Leetcode
Leetcode 1688. Count of Matches

Leetcode 1688. Count of Matches

作者: SnailTyan | 来源:发表于2021-09-10 10:48 被阅读0次

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

Count of Matches in Tournament

2. Solution

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

  • Version 1
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/

相关文章

网友评论

    本文标题:Leetcode 1688. Count of Matches

    本文链接:https://www.haomeiwen.com/subject/qkecbltx.html