class Solution {
public:
bool isPowerOfTwo(int n) {
double temp = log(n)/log(2);
int intTemp = (int)(temp+0.5);
if(abs(temp-intTemp)<1e-10)
return true;
else return false;
}
};
@marksim said in C++,6ms,no loop. The method is the same as Power of Three:
add
becaues the double temp value can be 4.9999 , the result of (int) is 4 , not 5.