1 public class Solution {
 2     public boolean isPowerOfThree(int n) {
 3         while (n > 1) {
 4             if (n % 3 != 0) {
 5                 return false;
 6             }
 7             n /= 3;
 8         }
 9         return n == 1;
10     }
11 }

 

 

1 public class Solution {
2     public boolean isPowerOfThree(int n) {
3         double a = Math.log(n) / Math.log(3);
4         return Math.abs(a - Math.rint(a)) <= 0.00000000000001;
5     }
6 }

 

posted on 2016-07-02 05:58  keepshuatishuati  阅读(116)  评论(0编辑  收藏  举报