码迷,mamicode.com
首页 > 其他好文 > 详细

326. Power of Three

时间:2016-07-09 23:38:35      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

    /*
     * 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;
    }

 

326. Power of Three

标签:

原文地址:http://www.cnblogs.com/zmyvszk/p/5656802.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!