---
# System prepended metadata

title: 'Leetcode [No.1688] Count of Matches in Tournament (EASY)'
tags: [leetcode]

---

# Leetcode [No.1688] Count of Matches in Tournament (EASY)

## 題目

https://leetcode.com/problems/count-of-matches-in-tournament/

## 思路
+ 這個題目主要的目的就是要你算match過幾次，所以把他加總起來就行了^_<
```c++

class Solution {
public:
    int numberOfMatches(int n) {
        int sum = 0;
        while(n!=1)
        {
            int matches = match(n);
            n = n - matches;
            sum+=matches;
        }
        return sum;
    }
    
    int match(int teams)
    {
        if(teams % 2 == 0)
        {
            return teams / 2;
        }
        else
        {
            return (teams -1) /2 ;
        }
    }
};

```

### 解法分析
+ time complexity: O(n)


### 執行結果

![image](https://hackmd.io/_uploads/ryYsd-fIT.jpg)
