Simple Java solution


  • 0

    '''
    public int findComplement(int num) {
    int compNum = 0;
    int indx = 0;
    while(num != 0){
    int bit = num % 2 == 0 ? 1:0;
    compNum += bit*Math.pow(2, indx);
    indx++;
    num /= 2;
    }
    return compNum;
    }
    ''''


Log in to reply
 

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