标签:
该题最简单的办法是迭代除2直到不能再除,看余数是否为1,更好的办法暂时没有想到。
class Solution {
public:
bool isPowerOfTwo(int n) {
if(n < 1)
return false;
while(n > 1){
if(n % 2 == 1)
return false;
n /= 2;
}
return true;
}
};版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/ny_mg/article/details/46848515