Beating 90% of the solutions


  • 0
    S
    public  static int findComplement(int num) {
            int i = 1;
            int multiplier = 2;
            int temp = num;
            temp = temp >> 1;
            while(temp != 0){
                temp = temp >> 1;
                i += multiplier;
                multiplier *= 2;
            }
    
            return num ^ i;
    
        }
    
    

Log in to reply
 

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