326. Power of Three

Given an integer, write a function to determine if it is a power of three.

Follow up:
Could you do it without using any loop / recursion?

javascript:

/**
 * @param {number} n
 * @return {boolean}
 */
var isPowerOfThree = function(n) {
    var num=Math.log(n)/Math.log(3);
    var num1=Math.abs(num-Math.round(num));
    if(num1<=0.00000000001)
    {
        return true;
    }
    else return false;
};
posted on 2016-03-10 16:44  baiyuhong  阅读(107)  评论(0编辑  收藏  举报