首页 » 编程之美 » 正文

[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 />
    }
};

发表评论

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax