地址:1688. 比赛中的配对次数
结果:AC
代码:
class Solution {
public:
int numberOfMatches(int n) {
if(n == 1) return 0;
if(n == 2) return 1;
if(n == 3) return 2;
else if(n % 2 == 0){
return (n/2) + numberOfMatches(n/2);
} else {
return ((n - 1) / 2) + numberOfMatches((n - 1) / 2 + 1);
}
}
};