题目:
Given an integer, write a function to determine if it is a power of two.
分析:
利用cpp函数log即可,注意当integer==0时的特殊情况。
代码:
class Solution {
public:
bool isPowerOfTwo(int n) {
if (n==0)return false;
int i=log(n)/log(2);
if(pow(2,i)==n)return true;
else return false;
}
};