일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 10분
- 30분
- 월간
- 개발자
- English
- 쓰릴오브파이트
- 프로젝트
- 리얼 클래스
- 사이드
- 괜찮음
- 매일
- realclass
- FIT XR
- 스탭퍼
- 읽기
- 미드시청
- 잡생각
- 링피트
- 영어공부
- 영어원서읽기
- 운동
- 뭐든
- leetcode
- 3줄정리
- Writing
- 파비최
- 만화도
- Daily Challenge
- Problem Solving
- 화상영어
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.12.02 Today's Challenge 본문
Minimum One Bit Operations to Make Integers Zero - LeetCode
Can you solve this real interview question? Minimum One Bit Operations to Make Integers Zero - Given an integer n, you must transform it into 0 using the following operations any number of times: * Change the rightmost (0th) bit in the binary representatio
leetcode.com
DP로 푸는 문제
class Solution:
def minimumOneBitOperations(self, n: int) -> int:
if not n:
return 0
k, curr = 0, 1
while (curr * 2) <= n:
curr *= 2
k += 1
return 2 ** (k+1) - 1 - self.minimumOneBitOperations(n ^ curr)
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.12.04 Today's Challenge (1) | 2023.12.04 |
---|---|
2023.12.03 Today's Challenge (0) | 2023.12.03 |
2023.12.01 Today's Challenge (0) | 2023.12.01 |
2023.11.30 Today's Challenge (0) | 2023.11.30 |
2023.11.29 Today's Challenge (0) | 2023.11.29 |
Comments