3 line C++ solution


  • 3
    int findComplement(int num) {
            int revert = ~0;
            while(revert & num ) revert <<= 1;
            return revert ^ (~num);
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.