Question:
Solution:
1 | public int bitwiseComplement(int N) { |
eg:
N=10, ans = 5 = 16 - 10 - 1
N=7, ans = 0 = 8 - 7 -1
N=5, ans = 2 = 6 -5 -1
Analyze:
N = 10, binaryN 1010
ans = 5,binaryA 0101
binaryN + binaryA = 1111
binaryN + binaryA + 1= 10000
so, binaryA = 10000 - binaryN - 1