class Solution:
def numberOfMatches(self, n: int) -> int:
ans = 0
while n > 1: # 循环加,每次都判断
if n % 2 == 0:
ans += n // 2
n //= 2
else:
ans += (n - 1) // 2
n = (n - 1) // 2 + 1
return ans
[leetcode 2022-01-27] 二、比赛中的配对次数
猜你喜欢
转载自blog.csdn.net/weixin_45492560/article/details/122710832
今日推荐
周排行