326. Power of Three

来源:互联网 发布:淘宝助理批量删除描述 编辑:程序博客网 时间:2024/06/04 19:10

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?

public class Solution {      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;      }  }  
原创粉丝点击