326. Power of Three

Given an integer, write a function to determine if it is a power of three.

题目含义:给定一个数,判断它是否是3的n次方

思路:使用换底公式

1     public boolean isPowerOfThree(int n) {
2         double res = Math.log10(n) / Math.log10(3);  //有精度问题,不要用以指数2.718为低的log函数  
3         return (res - (int)res == 0) ? true : false;      
4     }

 

posted @ 2017-10-20 20:36  daniel456  阅读(110)  评论(0编辑  收藏  举报