首页 » 编程之美 » 正文

[leetcode]Number Complement

class Solution {
public:
    int findComplement(int num) {
        int countDigit = 0;
        int numBak = num;
        while(0 < num) {
            num = num >> 1;
            countDigit++;
        }
        return (int)(pow(2, countDigit) - 1 - numBak);<br />
    }
};

发表评论