class Solution {
public int numberOfMatches(int n) {
if (n == 1)
return 0;
//偶数情况处理
if (n % 2 == 0) {
return numberOfMatches(n / 2) + n / 2;
//奇数情况处理
} else {
return numberOfMatches((n - 1) / 2 + 1) + (n - 1) / 2;
}
}
}
leetcode 1688. 比赛中的配对次数
最新推荐文章于 2022-02-04 22:46:15 发布