326. Power of Three
主要注意的是精读判断问题,使用round()函数进行四舍五入的取整数
判断精读的是方法是使用一个static的变量 double epsilon = 10e-15;
之后用abs()函数判断两个数之差是否在这个范围内即可。
#include <cmath>
class Solution {
public:
bool isPowerOfThree(int n) {
double epsilon = 10e-15;
if(n<=0)
return false;
else if(n==1)
return true;
else
{
double res=log(n)/log(3);
return abs(res-round(res))<epsilon;
}
}
};

浙公网安备 33010602011771号