Skip to content

Commit 6b94632

Browse files
committed
O(n) time and O(n) space
1 parent d046ca9 commit 6b94632

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+
class Solution(object):
2+
def findComplement(self, num):
3+
"""
4+
:type num: int
5+
:rtype: int
6+
"""
7+
final_str = ''
8+
bin_num = "{0:b}".format(num)
9+
def flip(c):
10+
return '1' if c=='0' else '0'
11+
for char in str(bin_num):
12+
final_str += flip(char)
13+
return int(final_str,2)

0 commit comments

Comments
 (0)