Leetcode 1806 Solution

This article provides solution to leetcode question 1806 (count-of-matches-in-tournament)

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; } };