1688. Count of Matches in Tournament Easy
1/**
2 * [1688] Count of Matches in Tournament
3 *
4 * You are given an integer n, the number of teams in a tournament that has strange rules:
5 *
6 * If the current number of teams is even, each team gets paired with another team. A total of n / 2 matches are played, and n / 2 teams advance to the next round.
7 * If the current number of teams is odd, one team randomly advances in the tournament, and the rest gets paired. A total of (n - 1) / 2 matches are played, and (n - 1) / 2 + 1 teams advance to the next round.
8 *
9 * Return the number of matches played in the tournament until a winner is decided.
10 *
11 * Example 1:
12 *
13 * Input: n = 7
14 * Output: 6
15 * Explanation: Details of the tournament:
16 * - 1st Round: Teams = 7, Matches = 3, and 4 teams advance.
17 * - 2nd Round: Teams = 4, Matches = 2, and 2 teams advance.
18 * - 3rd Round: Teams = 2, Matches = 1, and 1 team is declared the winner.
19 * Total number of matches = 3 + 2 + 1 = 6.
20 *
21 * Example 2:
22 *
23 * Input: n = 14
24 * Output: 13
25 * Explanation: Details of the tournament:
26 * - 1st Round: Teams = 14, Matches = 7, and 7 teams advance.
27 * - 2nd Round: Teams = 7, Matches = 3, and 4 teams advance.
28 * - 3rd Round: Teams = 4, Matches = 2, and 2 teams advance.
29 * - 4th Round: Teams = 2, Matches = 1, and 1 team is declared the winner.
30 * Total number of matches = 7 + 3 + 2 + 1 = 13.
31 *
32 *
33 * Constraints:
34 *
35 * 1 <= n <= 200
36 *
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/count-of-matches-in-tournament/
41// discuss: https://leetcode.com/problems/count-of-matches-in-tournament/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46 pub fn number_of_matches(n: i32) -> i32 {
47 0
48 }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_1688() {
59 }
60}
61
Back
© 2025 bowen.ge All Rights Reserved.