0
点赞
收藏
分享

微信扫一扫

leetcode1688. 比赛中的配对次数(easy)

代码小姐 2022-01-26 阅读 67
leetcode

比赛中的配对次数


力扣链接

解题思路

官方题解

代码(模拟)

	//模拟
    public int numberOfMatches(int n) {
        int count = 0;
        while (n > 1) {
            if ((n & 1) == 1) {
                count += (n - 1) / 2;
                n -= (n - 1) / 2;
            } else {
                count += n / 2;
                n /= 2;
            }
        }

        return count;
    }

代码(数学)

	public int numberOfMatches(int n) {
        return n - 1;
    }
举报

相关推荐

0 条评论