Thursday, February 18, 2021

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

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