C solution


  • 0
    G

    My simple C solution
    int findComplement(int num)
    {
    int result = 0;
    for(int i=0; i<32 && num>0; num>>=1, ++i)
    {
    if(num % 2 == 0)
    result += 1<<i;
    }
    return result;
    }


Log in to reply
 

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