일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- realclass
- Writing
- 3줄정리
- 화상영어
- 읽기
- 10분
- 운동
- 개발자
- Daily Challenge
- Problem Solving
- FIT XR
- 사이드
- 스탭퍼
- 영어공부
- 잡생각
- 매일
- 괜찮음
- 프로젝트
- 월간
- English
- 리얼 클래스
- 쓰릴오브파이트
- 30분
- 파비최
- 영어원서읽기
- leetcode
- 만화도
- 미드시청
- 링피트
- 뭐든
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.06.07 Today's Challenge 본문
https://leetcode.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/
Minimum Flips to Make a OR b Equal to c - LeetCode
Can you solve this real interview question? Minimum Flips to Make a OR b Equal to c - Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation). Flip operation consist
leetcode.com
비트 연산을 활용한 문제.
대부분의 문제가 그렇듯, 역으로 따져 올라가면 된다.
class Solution:
def minFlips(self, a: int, b: int, c: int) -> int:
answer = 0
while a or b or c:
if c & 1:
answer += 0 if ((a & 1) or (b & 1)) else 1
else:
answer += (a & 1) + (b & 1)
a >>= 1
b >>= 1
c >>= 1
return answer
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.06.09 Today's Challenge (0) | 2023.06.09 |
---|---|
2023.06.08 Today's Challenge (0) | 2023.06.08 |
2023.06.06 Today's Challenge (0) | 2023.06.06 |
2023.06.05 Today's Challenge (0) | 2023.06.05 |
2023.06.04 Today's Challenge (0) | 2023.06.04 |
Comments