# 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) ### 執行結果 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up