My code:
public class Solution {
public boolean isPowerOfThree(int n) {
return n > 0 && Math.pow(3, (int) (Math.log(Integer.MAX_VALUE) / Math.log(3))) % n == 0;
}
}
reference:
这个解释最实用
https://discuss.leetcode.com/topic/44183/java-one-line-solution
这个解释最全面
https://leetcode.com/articles/power-of-three/
Anyway, Good luck, Richardo! — 10/14/2016