leetcode 326 Power of Three C++
来源:互联网 发布:300英雄淘宝店 编辑:程序博客网 时间:2024/06/09 13:44
题意是看是否是3的幂,简单的做法:
bool isPowerOfThree(int n) { for (int i = 0;;i++){ if (pow(3,i)>n) return false; if (pow(3,i) == n) return true; } return false; }
不用递归和循环的做法,利用了log函数,不能直接用log,因为当log(243)的时候,会因为精度的问题出现错误。
return fmod(log10(n)/log10(3), 1)==0;
fmod这个函数求余后能够取得小数点后面的部分,直接求余不行。
0 0
- 【LeetCode-326】Power of three 上(C++)
- 【LeetCode-326】Power of three 下(C++)
- 【C语言】 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
- (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
- 2016 -Nginx的负载均衡 - 一致性哈希 (Consistent Hash)
- app移动端H5页面开发调试之Chrome远程调试
- DB sharding and ID design
- HTML::LinkExtor, links(), parse_file()
- c++第6次实验
- leetcode 326 Power of Three C++
- 在less中使用css3 calc 的问题
- android自定义viewGroup 不显示问题
- Logback 使用配置及问题
- Net::Telnet, open(), print(), getline()
- 排序算法稳定性分析
- Android学习系列(13)--App列表之游标ListView(索引ListView)
- AppDomain类理解
- Compress::Zlib, gzopen(), gzreadline(), gzclose()