Leetcode 326 Power of Three 数论
判断一个数是否是3的n次幂
这里我用了一点巧,所有的int范围的3的n次幂是int范围最大的3的n次幂数(即3^((int)log3(MAXINT)) = 1162261467)的约数
这种方法是我目前觉得是最好的,不容易出错,其他的方法因为精度问题而很容易错。
class Solution {
public:
bool isPowerOfThree(int n) {
if(n>) return %n==;
else return false;
}
};
Leetcode 326 Power of Three 数论的更多相关文章
- leetcode 326. Power of Three(不用循环或递归)
leetcode 326. Power of Three(不用循环或递归) Given an integer, write a function to determine if it is a pow ...
- 39. leetcode 326. Power of Three
326. Power of Three Given an integer, write a function to determine if it is a power of three. Follo ...
- [LeetCode] 326. Power of Three 3的次方数
Given an integer, write a function to determine if it is a power of three. Follow up:Could you do it ...
- LeetCode 326 Power of Three
Problem: Given an integer, write a function to determine if it is a power of three. Could you do it ...
- Leetcode 342 Power of Four 数论
题意:判断一个数是不是4的幂数,和Power of two类似. 先判断num是否大于0,再判断num是否能开根号,最后判断num开根号后的数是否是2^15的约数. 提示:4的幂数开根号就是2的幂数. ...
- Leetcode 231 Power of Two 数论
同样是判断数是否是2的n次幂,同 Power of three class Solution { public: bool isPowerOfTwo(int n) { ) && ((( ...
- Java [Leetcode 326]Power of Three
题目描述: Given an integer, write a function to determine if it is a power of three. Follow up:Could you ...
- LeetCode 326 Power of Three(3的幂)(递归、Log函数)
翻译 给定一个整型数,写一个函数决定它是否是3的幂(翻译可能不太合适-- 跟进: 你能否够不用不论什么循环或递归来完毕. 原文 Given an integer, write a function t ...
- leetcode 326 Power of Three (python)
原题: Given an integer, write a function to determine if it is a power of three. Follow up: Could you ...
随机推荐
- HTML5和CSS3基础教程(第8版)-读书笔记
第1章 网页的构造块 一个网页主要包括以下三个部分: n 文本内容(text content):在页面上让访问者了解页面内容的纯文字. n 对其他文件的引用(referen ...
- UIWebView使用时的问题,包含修改user agent
1.①像普通controller那样实现跳转到webview的效果,而不是直接加到当前controller②隐藏webview的某些元素③webview跳往原生app④给webview添加进度条 解决 ...
- andorid service 本地服务
ActivityManifect.xml <?xml version="1.0" encoding="utf-8"?> <manifest x ...
- dom相关指令
1.ng-show 和 ng-hide 当ng-show=''true''的时候 dom会显示,反之隐藏,通过控制display属性 2.ng-if 当ng-if=“true” 的时候,dom显示, ...
- css 常用样式
1. border-radius - 指定每个圆角 四个值: 第一个值为左上角,第二个值为右上角,第三个值为右下角,第四个值为左下角. 三个值: 第一个值为左上角, 第二个值为右上角和左下角,第三个值 ...
- (Python) 函数、匿名函数
本节将学习如何用Python定义函数,调用函数,以及学习匿名函数的使用 1.定义函数 Python中定义函数用关键字def,如下例所示,testFun为函数名 def testFun(): print ...
- SQL 修改列名
exec sp_rename 'student.Ssex','Sex','column'; 执行后就可达到目的. 即是运用了 exec sp_rename '表明.原列名','新列名','column ...
- Excel VBA自动添加证书(二)
继续上次没有写完的随笔,本来是很想一次性写完的,但是到中午一点了还没有吃东西,其实饿的不行了,还好写博客时会自动保存,中间电脑实然蓝屏,花了二个多小时写的没有点击保存,吓我一下,以为会全没了. 前面讲 ...
- 使用PPT绘制96孔板
什么?96孔板就是Ctrl+C然后再Ctrl+V? 那你用PPT给我画一个384孔板吧……(学生物的应该都知道这货吧?示意图不少用吧?) 还不够麻烦?那就试试基因芯片吧…… 疯掉了有木有? 那么,看看 ...
- OkHttp使用进阶 译自OkHttp Github官方教程
版权声明: 欢迎转载,但请保留文章原始出处 作者:GavinCT 出处:http://www.cnblogs.com/ct2011/p/3997368.html 没有使用过OkHttp的,可以先看Ok ...