标签:
No loop; No recursion; 我没找到规律 但是从讨论区看到别人的思路:
If N
is a power of 3
:
3^X == N
log (3^X) == log N
X log 3 == log N
X == (log N) / (log 3)
X
must be an integer.代码:
public class Solution { public boolean isPowerOfThree(int n) { double diff = 10e-15; double x = Math.log(n)/Math.log(3); return Math.abs( x - Math.round(x)) <= diff; } }
Jan 14 - Power of three; Math; Integer; Digit;
标签:
原文地址:http://www.cnblogs.com/5683yue/p/5132198.html