Easy C Solution


  • 0
    M

    '''
    int findComplement(int num) {
    if(num == 1) return 0;
    int twoPower = 1;

    for(int i = 1; i <=31;i++){
        if(num > twoPower){
            twoPower = twoPower << 1;
        }
        else if(num == twoPower){
            return num-1;
        }
        else if(num < twoPower){
            break;
        }        
    }
    twoPower -= 1;
    return (num ^ twoPower);
    

    }'''


Log in to reply
 

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