Not sure if it's a good solution but it's pretty fast


  • 0
    G
    public int findComplement(int num) {
            int zeros = Integer.numberOfLeadingZeros(num);
            return ((num << zeros ) ^ 0xffffffff) >> zeros;
        }
    

Log in to reply
 

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