Re: Error in Power of Two question
Question: why wrong when I cut down the final abs???
//right version
class Solution {
public:
bool isPowerOfTwo(int n) {
double x = log(n) / log(2);
return (abs((x  (int)(x+0.5)))< 1e10); //why wrong when I cut down the abs???
}
};
//wrong version:
class Solution {
public:
bool isPowerOfTwo(int n) {
double x = log(n) / log(2);
return ((x  (int)(x+0.5))< 1e10); //why wrong when I cut down the abs???
}
};
Question in 231. Power of Two


@sugan
please say something about which part you do not understand, and it will convient me. And my code is based on knowledge of log.

@Offer2017
Hi,
actually I dont understand how you are using log to get to the solution. And why do u do log(n)/log(2).
And what does the return statement mean.