Skip to content

Commit eff3567

Browse files
committed
day12
1 parent 1ac7a96 commit eff3567

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def findComplement(self, num: int) -> int:
3+
cnt = 0
4+
5+
# 2진수 최대 - 1 - num 으로 답을 구할 수 있음
6+
# 예) num = 14라면 2^4 - 1 - 14 = 1이 답임
7+
# 예) num = 24라면 2^5 - 1 - 24 = 7이 답임
8+
def makeBinary(num: int):
9+
nonlocal cnt
10+
cnt += 1
11+
if num // 2 == 0:
12+
return
13+
makeBinary(num // 2)
14+
15+
makeBinary(num)
16+
return 2 ** cnt - num - 1
17+

0 commit comments

Comments
 (0)