Power of Three

来源:互联网 发布:多客户端访问数据库 编辑:程序博客网 时间:2024/06/05 12:39

这个掌握最基本的迭代就好。

public class Solution {    public boolean isPowerOfThree(int n) {        if (n == 0) {            return false;        }        return n == Math.pow(3, Math.round(Math.log(n)/Math.log(3)));    }            // public boolean isPowerOfThree(int n) {    //     while (n > 0 && n % 3 == 0) {    //         n = n/3;    //     }    //     return n == 1;    // }}



0 0