问题
思路
n&(n-1)的妙用。
它的作用是把位向量当中,最低位的1置0;
代码
class Solution {
public:
bool isPowerOfTwo(int n) {
return ( n > 0 && !(n&(n-1)) );
}
};
n&(n-1)的妙用。
它的作用是把位向量当中,最低位的1置0;
class Solution {
public:
bool isPowerOfTwo(int n) {
return ( n > 0 && !(n&(n-1)) );
}
};