Problem 326: Power of Three
思路
等价于
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;
}
}
Last updated
Was this helpful?