LeetCode 1688. Matches in the match

Give you an integer n, which represents the number of teams in the game. The competition follows a unique format:

If the current number of teams is even, then each team will be paired with another team. A total of n / 2 games are played, and n / 2 teams are generated to enter the next round.
If the current number of teams is an odd number, then a random bye will be made and one team will be promoted, and the remaining teams will be matched. A total of (n-1) / 2 games are played, and (n-1) / 2 + 1 teams are generated to enter the next round.
Returns the number of matchmaking in the game until the winning team is determined.

Since each match will eliminate one team, the number of matches is the total number of teams-1:

class Solution {
    
    
public:
    int numberOfMatches(int n) {
    
    
        return n - 1;
    }
};

Guess you like

Origin blog.csdn.net/tus00000/article/details/112162563