326. Power of Three

    /*
     * 326. Power of Three
     * 2016-7-8 by Mingyang
     * 中规中矩,不过注意,n不能为0,不然while一直走,也不能为负
     * 时间logn,空间到是没有要求
     */
    public boolean isPowerOfThree(int n) {
        if (n < 1) {
            return false;
        }
        while (n % 3 == 0) {
            n /= 3;
        }
        return n == 1;
    }
原文地址:https://www.cnblogs.com/zmyvszk/p/5656802.html