Thursday, February 18, 2021

Leetcode Everyday: 1688. Count of Matches in Tournament. Easy

1
2
3
4
5
6
7
8
9
10
11
12
public class Solution {
    public int NumberOfMatches(int teams) {         
        int matchesSum = 0;
        while (teams > 1) {
            int matches = teams / 2;
            matchesSum += matches;                       
            teams -= matches;  
        }
         
        return matchesSum;
    }
}
Source: https://leetcode.com/problems/count-of-matches-in-tournament/

No comments:

Post a Comment