Leetcode_1688_比赛中的配对次数_水题

12/13

水题

class Solution {
    
    
    public int numberOfMatches(int n) {
    
    
        int ans=0;
        while(n!=1){
    
    
            ans+=n/2;
            n=(n+1)/2;
        }
        return ans;
    }
}

猜你喜欢

转载自blog.csdn.net/HDUCheater/article/details/111098068