计算机Leetcode, again

Leetcode - Power of Three

2016-10-15  本文已影响8人  Richardo92

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

上一篇下一篇

猜你喜欢

热点阅读