일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 3줄정리
- 링피트
- 쓰릴오브파이트
- 월간
- Daily Challenge
- 뭐든
- 미드시청
- 10분
- 읽기
- 영어공부
- 운동
- 영어원서읽기
- 30분
- 매일
- English
- 리얼 클래스
- 파비최
- 괜찮음
- 잡생각
- 개발자
- leetcode
- Writing
- 만화도
- 사이드
- FIT XR
- Problem Solving
- 화상영어
- 프로젝트
- 스탭퍼
- realclass
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