Power of Three 带测试版

来源:互联网 发布:程序员的英语单词 编辑:程序博客网 时间:2024/05/17 21:45
public class Solution326 {     public boolean isPowerOfThree(int n) {          double temp = 10e-15;          if(n==0) return false;          double res = Math.log(n) / Math.log(3);          return Math.abs(res-Math.round(res)) < temp;  //或者Math.rint();    }      public static void main(String[]args)    {        int n=243;        System.out.println(isPowerOfThree(n));    }}
0 0
原创粉丝点击