Skip to content

Latest commit

 

History

History
31 lines (27 loc) · 517 Bytes

1688. 比赛中的配对次数.md

File metadata and controls

31 lines (27 loc) · 517 Bytes
  • 常规解法
/**
 * @param {number} n
 * @return {number}
 */
var numberOfMatches = function (n) {
    let sum = 0;
    while (n !== 1) {
        const match = Math.floor(n / 2);
        sum += match;
        n = Math.ceil(n / 2);
    }
    return sum;
};
  • 数学解法
/**
 * @param {number} n
 * @return {number}
 */
var numberOfMatches = function (n) {
    return n - 1;
};