Skip to content

Commit fbc3d13

Browse files
authored
Update 0476. Number Complement.txt
1 parent 6a276d7 commit fbc3d13

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

0476. Number Complement.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public int findComplement(int num) {
3+
// example:
4+
// num = 5(101)
5+
// highestOneBit of 101 is 100
6+
// highestOneMinusOne = 100 << 1, minus 1 = 0111
7+
int highestOneMinusOne = (Integer.highestOneBit(num) << 1) - 1;
8+
// ~ num = 1010
9+
return ~ num & highestOneMinusOne;
10+
}
11+
}

0 commit comments

Comments
 (0)