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)
本题就是证明是不是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)
相关文章推荐
- codeforce 474D Flowers
- 进程间通信
- iOS之通过NSOutputStream大文件下载
- 面试题8 旋转数组的最小数字
- Java集合框架之Set--HashSet源码分析
- 利用贝塞尔曲线实现小球曲线运动
- Fibonacci(POJ3070)
- Linux USB 驱动开发(四)—— 热插拔那点事
- 对URL的使用
- MySQL 使用方法简单教程
- Tcl -- split/join
- PHP开源框架Laravel的安装与配置
- 114. Flatten Binary Tree to Linked List
- Oracle12c功能增强 新特性之管理功能的增强
- 做一个领导喜欢的员工
- pwnable之coin1
- 欢迎使用CSDN-markdown编辑器
- 太空3D
- 005 ZeroMQ REQ-<ROUTER-Dealer>-REP代理应答与请求
- POJ 3420 (矩阵二分幂优化,状压DP)