题:比赛有n个队伍,每轮淘汰一半,如果n是奇数,那么多的一个队伍直接晋级。
求总共的比赛次数。
解:(模拟)
class Solution: def numberOfMatches(self, n: int) -> int: res = 0 while n > 1: res += n//2 n = (n+1) // 2 return res
本文分享自 一只大鸽子 微信公众号,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文参与 腾讯云自媒体同步曝光计划 ,欢迎热爱写作的你一起参与!