일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- leetcode
- 링피트
- 영어공부
- FIT XR
- 미드시청
- 만화도
- 뭐든
- 매일
- 화상영어
- realclass
- 파비최
- 10분
- 리얼 클래스
- 프로젝트
- 읽기
- Daily Challenge
- 운동
- English
- 사이드
- 30분
- 쓰릴오브파이트
- 월간
- 개발자
- 영어원서읽기
- Problem Solving
- 잡생각
- Writing
- 괜찮음
- 스탭퍼
- 3줄정리
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.12.06 Today's Challenge 본문
https://leetcode.com/problems/count-of-matches-in-tournament/
Count of Matches in Tournament - LeetCode
Can you solve this real interview question? Count of Matches in Tournament - You are given an integer n, the number of teams in a tournament that has strange rules: * If the current number of teams is even, each team gets paired with another team. A total
leetcode.com
매우 간단한 문제.
다만 base case에 대한 더 깔끔한 처리 방법이 있으면 좋겠음.
class Solution:
def numberOfMatches(self, n: int) -> int:
if n == 1:
return 0
if n == 2:
return 1
cnt = 0
while n > 2:
if n % 2:
cnt += (n - 1) // 2
n = (n - 1) // 2 + 1
else:
n = n // 2
cnt += n
return cnt + 1
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.12.08 Today's Challenge (0) | 2023.12.08 |
---|---|
2023.12.07 Today's Challenge (0) | 2023.12.07 |
2023.12.05 Today's Challenge (0) | 2023.12.05 |
2023.12.04 Today's Challenge (1) | 2023.12.04 |
2023.12.03 Today's Challenge (0) | 2023.12.03 |
Comments