比赛中的配队次数【水题】

题目链接

解题思路:简单模拟即可

class Solution {
public:
    int numberOfMatches(int n) {
        int sum=0;
        while(n!=1){
            if(n%2==0){
                n=n>>1;
                sum+=n;
            }
            else{
                n=n>>1;
                sum+=n;
                n++;
            }
        }
        return sum;
    }
};
posted @ 2022-01-25 18:02  夜灯长明  阅读(8)  评论(0编辑  收藏  举报