반응형
오늘 풀 문제는 Count of Matches in Tournament라는 문제이며
링크는 leetcode.com/problems/count-of-matches-in-tournament/입니다
이 문제는 간단한 문제로 경기수를 구하는 문제입니다. 경기수는 계속 2로 나눈 몫을 더하면 되고 경기수는 2로 나눈 나머지와 몫을 계속 더해주는 식으로 구하면 됩니다
코드는 아래와 같습니다
func numberOfMatches(n int) int {
res := 0;
for n > 1 {
rem_num := n%2;
div_num := n/2;
n = rem_num + div_num;
res += div_num;
}
return res;
}
감사합니다!
'Language > Go' 카테고리의 다른 글
[Golang으로 도전하는 Leetcode] Partitioning Into Minimum Number Of Deci-Binary Numbers (0) | 2020.12.16 |
---|---|
[Golang으로 도전하는 Leetcode] Max Number of K-Sum Pairs (0) | 2020.12.12 |
[Golang으로 도전하는 Leetcode] Goal Parser Interpretation (0) | 2020.12.09 |
[Golang으로 도전하는 Leetcode] Goal Parser Interpretation (0) | 2020.12.09 |
[Golang으로 도전하는 Leetcode] Richest Customer Wealth (0) | 2020.12.04 |