problem

​231-power-of-two​

 solution1

class Solution {
public:
bool isPowerOfTwo(int n) {
if(n==0) return false;
while(n%2==0)
{
n /= 2;
}
return n==1;
}
};

View Code

solution2

【leetcode】231-power-of-two_其它

【leetcode】231-power-of-two_其它_02

class Solution {
public:
bool isPowerOfTwo(int n) {
if(n<=0) return false;
return !(n&(n-1));
}
};

View Code

 

 

 

参考

1. ​​Leetcode_231-power-of-two​​;