image.png
技巧性非常強(qiáng)
如果是2的冪次方 則有(x & (x-1) == 0)
class Solution {
public:
bool isPowerOfTwo(int n) {
if(n < 1) return false;
return (n & (n-1)) == 0;
}
};
技巧性非常強(qiáng)
如果是2的冪次方 則有(x & (x-1) == 0)
class Solution {
public:
bool isPowerOfTwo(int n) {
if(n < 1) return false;
return (n & (n-1)) == 0;
}
};