231.Power of Two
示例 1:
输入: 1
输出: true
解释: 20 = 1
示例 2:
输入: 16
输出: true
解释: 24 = 16
示例 3:
输入: 218
输出: falseclass Solution {
public:
bool isPowerOfTwo(int n) {
if(n==0) return false;
while((n&1) ==0)
{
n>>=1;
}
// cout<<n<<endl;
return n==1;
}
};Last updated