476. Number Complement ¶ Time: $O(32) = O(1)$ Space: $O(1)$ C++Java 1 2 3 4 5 6 7 8class Solution { public: int findComplement(long num) { for (long i = 1; i <= num; i <<= 1) num ^= i; return num; } }; 1 2 3 4 5 6 7class Solution { public int findComplement(int num) { for (long i = 1; i <= num; i <<= 1) num ^= i; return num; } }