[326]Power of Three
来源:互联网 发布:淘宝生产许可证 编辑:程序博客网 时间:2024/05/16 06:44
【题目描述】
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?
如果是3的幂必然取以3为底的对数得到的是整数,而stl库里有log的函数,因此只要判断是否以3为底的对数是否为整数即可
【代码】
class Solution {public: bool isPowerOfThree(int n) { double ans=log10(n)/log10(3); return (ans-int(ans))==0?true:false; }};
0 0
- [326] Power of Three
- [326]Power of Three
- leetcode-326-Power of Three
- [LeetCode 326] Power of Three
- LeetCode 326:Power of Three
- Leetcode 326:Power of Three
- leetcode-326-Power of Three
- LeetCode 326 Power of Three
- [LeetCode 326] Power of Three
- 326-e-Power of Three
- (LeetCode 326)Power of Three
- LeetCode-326 Power of Three
- LeetCode-326: Power of Three
- LeetCode 326 Power of Three
- Leetcode 326 : Power of Three
- Leetcode 326 Power of Three
- leetcode-326-Power of Three
- Leetcode 326 Power of Three
- 年中总结
- RedisCluster搭建步骤
- Jsp空间上TOMCAT报 error listenerstart错误的解决办法
- Window属性
- lighttpd 服务器搭建过程记录2【with CGI】
- [326]Power of Three
- 约瑟夫环二
- Centos7下启用端口
- 【负载均衡】openstack负载均衡之haproxy
- MongoDB资料大全
- 自己工作的一点感想
- MAC unity 双开
- The most orz man(单堆NIM)
- 我的软实力