容易理解的方法


  • -1
    D

    class Solution {
    public:
    int findComplement(int num) {
    int count=0;
    int num_temp=num;
    while(num_temp!=0)
    {
    count++;
    num_temp=num_temp>>1;
    }
    int sum=1;
    for(int i=0;i<count;i++)
    {
    sum=sum*2;
    }
    return sum-1-num;

    }
    

    };


Log in to reply
 

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