C++ solution


  • 0
    W

    class Solution {

    public:

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

    };


Log in to reply
 

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