标签:
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 { private static final double epsilon=10e-15; public boolean isPowerOfThree(int n) { if(n<=0){return false;} if(n==1){return true;} double res=Math.log(n)/Math.log(3); return Math.abs(res - Math.round(res)) < epsilon; } }
标签:
原文地址:http://www.cnblogs.com/incrediblechangshuo/p/5683302.html