Given an integer, write a function to determine if it is a power of three.
Follow up:
Could you do it without using any loop / recursion?
题意 :给定整数,判断是否为3的幂
解题思路:纯计算……
代码:
public boolean isPowerOfThree(int n) {
double a = Math.log(n) / Math.log(3);
return Math.abs(a - Math.rint(a)) <= 0.00000000000001;
}