231. Power of Two

Given an integer, write a function to determine if it is a power of two.

2的整数幂
1     (1)b
2     (10)b
4      (100)b
8       (1000)b
....
class Solution {
public:
    bool isPowerOfTwo(int n) {
        return n <= 0?false:!(n & (n-1));
    }
};

results matching ""

    No results matching ""