Skip to content

Commit

Permalink
Time: 41 ms (26.41%), Space: 16.5 MB (65.91%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhquy-nguyen-1704 committed Feb 16, 2024
1 parent 1ab6b0b commit 531b970
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions 0476-number-complement/0476-number-complement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution:
def findComplement(self, num: int) -> int:
st = ""
while num != 0:
st += str(num%2)
num = num//2

st2 = ""
for i in st:
if i == "0":
st2 += "1"
else:
st2 += "0"

dec = 0
for j in range(len(st2)):
if st2[j] == "1":
dec += 2**(j)

return dec


0 comments on commit 531b970

Please sign in to comment.