Share my Java solutiton


  • 0
    F
    public int findComplement(int num) {
            int res = 0;
            int countBit = 0;
            while(num > 0) {
                res = ((~num&1) << countBit)|res;
                countBit++;
                num>>=1;
            }
            return res;
        }
    

Log in to reply
 

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