您的位置:首页 > 其它

326. Power of Three

2016-04-04 16:09 267 查看
Given an integer, write a function to determine if it is a power of three.

本题就是证明是不是3的幂

public class Solution {

public boolean isPowerOfThree(int n) {

return n<=0?false:n==Math.pow(3,(Math.round(Math.log(n)/Math.log(3))));

}

}

思路就是3^x=n那么

x=log(n)/log(3)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: