Last updated 5 years ago
https://leetcode.com/problems/power-of-three/#/description
n=3mn = 3 ^ mn=3m 等价于 log(n)=m∗log(3)log(n) = m * log(3)log(n)=m∗log(3)
public class Solution { public boolean isPowerOfThree(int n) { return (Math.log10(n) / Math.log10(3)) % 1 == 0; } }
public class Solution { public boolean isPowerOfThree(int n) { if (n > 1) { while (n % 3 == 0) n /= 3; } return n == 1; } }