当前位置: 代码迷 >> 综合 >> Leetcode 1688. Count of Matches in Tournament
  详细解决方案

Leetcode 1688. Count of Matches in Tournament

热度:61   发布时间:2023-12-12 20:53:56.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 = 0while n != 1:matches = n // 2total += matchesif n % 2 == 0:n = matcheselse:n = matches + 1return total# return n - 1

Reference

  1. https://leetcode.com/problems/count-of-matches-in-tournament/
  相关解决方案