Skip to content

Commit 8dcb138

Browse files
authored
Create number_complement.py
1 parent 8d338cd commit 8dcb138

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

number_complement.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
"""
3+
@param num: an integer
4+
@return: the complement number
5+
"""
6+
def findComplement(self, num):
7+
# Write your code here
8+
i = 1
9+
while i <= num:
10+
i *= 2
11+
if i == num:
12+
return i - 1
13+
else:
14+
return i -1 - num
15+
16+
# easy: https://www.lintcode.com/problem/number-complement/

0 commit comments

Comments
 (0)