Given a positive integer num, return its complement, where every bit in the binary representation is flipped and leading zeros are ignored. Pattern focus: Check kth Bit. Build an all-ones mask up to the highest set bit, then flip only the relevant positions.
num = positive integer
bitwise complement of num
Example 1:
Input:
num = 5
Output:
2
Explanation:
5 is 101 in binary, and its complement is 010, which is 2.
Example 2:
Input:
num = 1
Output:
0
Explanation:
1 becomes 0 after flipping its single bit.