64,188
社区成员




1231. 2 的幂 - 力扣(LeetCode) (leetcode-cn.com)
//解法一:
// bool isPowerOfTwo(int n)
// {
// double i=log2(n);
// if(i==(int)i)
// return true;
// else
// return false;
// }
//解法二:
// bool isPowerOfTwo(int n)
// {
// if(n<=0)
// return false;
// if(n&(n-1))
// return false;
// return true;
// }
//解法三:
bool isPowerOfTwo(int n)
{
int i=0;
for(i=0;i<32;i++)
{
long long j=1;
j<<=i;
if(n==j)
return true;
}
return false;
}
2,326. 3 的幂 - 力扣(LeetCode) (leetcode-cn.com)
bool isPowerOfThree(int n)
{
int i=0;
int m=0;
for(i=0;i<10000;i++)
{
m=(int)pow(3,i);
if(m>n)
return false;
if(m==n)
return true;
}
return 0;
}
3,342. 4的幂 - 力扣(LeetCode) (leetcode-cn.com)
bool isPowerOfFour(int n)
{
double i=log2(n)/log2(4);
if(i==(int)i)
return true;
else
return false;
}