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 ...
随机推荐
- mysql处理字符串
1.从左开始截取字符串 left(str, length) 说明:left(被截取字段,截取长度) 例:select left(content,200) as abstract from my_con ...
- Python环境下NIPIR(ICTCLAS2014)中文分词系统使用攻略
一.安装 官方链接:http://pynlpir.readthedocs.org/en/latest/installation.html 官方网页中介绍了几种安装方法,大家根据个人需要,自行参考!我采 ...
- perl小记
perl是一种运行式脚本,所以在debug的时候,多用print,在后台看有没有输出相关的结果,来判断相应的错误. 部分perl正则表达式: $gene =~/^LOC/ 以“LOC”开头的字符串 ...
- mysql 4种启动方式
mysql 4种启动方式 都是去调用mysqld文件 1. mysqld 启动 进入mysqld文件所在目录(/../libexec/mysqld) ./mysqld --defaults-file= ...
- memalign vs malloc - 使用O_DIRECT参数open一个文件并读写
听说使用odirect参数打开文件时能够以扇区的单位进行读写. 于是open了一个块设备文件/dev/sdo,当然还要带上读写参数O_RDWR 然后进行读写时出错了. 找了一会发现问题根本在于读写的b ...
- 关于VMWARE 上对于不小心VMWare Tools Easy Install 后卡死的解决方法
PS 要想修改首先开机的时候会进入命令行,输入用户名,密码后,可以用startx来进入图形界面(也有人将/etc/init.d/ligtmd start可以懂事本人那次是不行的) 通常网上人们的解决办 ...
- ubuntu 14.04 编译内核出现unable to locate package ncurses-devel 问题的解决
http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380146d96864968d4e414c422461614 ...
- 用js识别是否360浏览器
360浏览器说实话比较恶,以前可以通过内核返回的字符串判定是否包含"360"字样的方法来判定 如以下代码 window.navigator.userAgent.indexOf('3 ...
- 再详细的介绍一下Unity5的AssetBundle
之前曾经写了一篇博客介绍Unity5的AssetBundle,结果似乎很受关注.不过似乎很多人看了之后都不懂,主要是因为不太明白AssetBundle是什么,它的依赖关系和结构是什么的,就直接想拿代码 ...
- Titanium系列--我常用的Titanium的快捷键(持续更新中。。)
Titanium快捷键: (注:Titanium属于eclipse系列的IDE) ctrl + shift + r 快速打开 ctrl + shift + e / ctrl + e 打开之前的文件 c ...