Leetcode 1806 Solution
This article provides solution to leetcode question 1806 (count-of-matches-in-tournament)
Access this page by simply typing in "lcs 1806" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/count-of-matches-in-tournament
Solution
class Solution {
public:
int numberOfMatches(int n) {
int s = 0;
while (n > 1)
{
if (n % 2)
{
s += (n - 1) / 2;
n = (n - 1) / 2 + 1;
}
else
{
s += n / 2;
n = n / 2;
}
}
return s;
}
};