【leetcode】数字的补数

 

int findComplement(int num){
    int sum =0,pst=0;
    while(num){
        if ((num & 1) == 0)
        {
            sum += pow(2,pst);            
        }
        num >>= 1;
        pst++;
    }
    return sum;
}

 

posted @ 2020-09-15 13:35  温暖了寂寞  阅读(149)  评论(0编辑  收藏  举报