Count of Matches in Tournament LeetCode solution in JavaScript

1
/**
2
* @param {number} n
3
* @return {number}
4
*/
5
var numberOfMatches = function (n) {
6
let matches = 0,
7
current = n;
8
while (current > 1) {
9
if (current % 2 === 0) {
10
matches += current / 2;
11
current = current / 2;
12
} else {
13
matches += (current - 1) / 2;
14
current = (current - 1) / 2 + 1;
15
}
16
}
17
return matches;
18
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0