Simple Java


  • 0
    E
    public int findComplement(int num) {
            int i = num;
            int mask = 1;
            while(i != 0) {
                num = num ^ mask;
                mask <<= 1;
                i >>= 1;
            }
            return num;
        }
    

Log in to reply
 

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