231. 2 的幂(c++)
作者:互联网
循环
class Solution {
public:
bool isPowerOfTwo(int n) {
for(int i = 0; i <= 31; i++){
if(pow(2,i) == n){
return true;
}
}
return false;
}
};
class Solution {
public:
bool isPowerOfTwo(int n) {
return n > 0 && (n & (n-1)) == 0;
}
};
class Solution {
public:
bool isPowerOfTwo(int n) {
return n > 0 && (n & (-n)) == n;
}
};
标签:return,int,Solution,c++,class,bool,isPowerOfTwo,231 来源: https://blog.csdn.net/qq_36421001/article/details/122786039