Leetcode--326. Power of Three
来源:互联网 发布:html5权威指南 源码 编辑:程序博客网 时间:2024/05/21 17:34
题目
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?
Credits:
Special thanks to @dietpepsi for adding this problem and creating all test cases.
不用循环或递归,判断一个数是否是3的x次方
思路
一个基本的事实就是如果n是3的x次方,那么以3为低对数后一定是一个整数,否则不是
代码
class Solution {public: bool isPowerOfThree(int n) { double res = log10(n) / log10(3); return (res-(int)(res)) == 0 ? true : false; }};
阅读全文
0 0
- [leetcode]326. Power of Three
- Leetcode 326. Power of Three
- Leetcode 326. Power of Three
- [leetcode] - 326. Power of Three
- 326. Power of Three LeetCode
- 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.[LeetCode]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
- socket是什么?在程序中是怎么实现的?
- Windows下对DB2-Express-C的操作命令
- [JZSC2017] 【NOIP2017提高组模拟6.30】总(翻车)结(记)
- 数据库多表关联查询
- Proving NP-completeness
- Leetcode--326. Power of Three
- Apache Flume
- 关于MFC消息的使用
- 查找字符串中出现最多次数的字符及其个数
- hadoop伪分布式搭建
- Spring的入门教程(1)
- ubuntu 安装中文输入法
- 纳税服务系统【投诉受理管理,显示投诉信息、处理回复、我要投诉】
- JZOJ 5185. 【NOIP2017提高组模拟6.30】tty's sequence