Leetcode Note: Go - Count of Matches in Tournament
Count of Matches in Tournament - LeetCode
https://leetcode.com/problems/count-of-matches-in-tournament/
- Go 言語で取り組んだメモ
回答
Go - simple solution - 100.00% of Go - Count of Matches in Tournament - LeetCode
https://leetcode.com/problems/count-of-matches-in-tournament/solutions/1008914/go-simple-solution-100-00-of-go/
func numberOfMatches(n int) int {
matches := 0
for n > 1 {
if (n%2 == 0) {
matches += (n / 2)
n = (n / 2)
} else {
matches += (n - 1) / 2
n = ((n-1)/2 + 1)
}
}
return matches
}