Skip to content

Commit fe01dc3

Browse files
authored
Create complement-of-base-10-integer.py
1 parent 69c6ae1 commit fe01dc3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Time: O(logn)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def bitwiseComplement(self, N):
6+
"""
7+
:type N: int
8+
:rtype: int
9+
"""
10+
mask = 1
11+
while N > mask:
12+
mask = mask*2+1
13+
return mask-N

0 commit comments

Comments
 (0)