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 ...
随机推荐
- java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.TextView
最近在学习drawerLayout时,遇到这个bug.如下示: java.lang.ClassCastException: android.widget.RelativeLayout cannot b ...
- vim global命令
global命令格式 : [range]global/{pattern}/{command} global命令在[range]指定的文本范围内(缺省为整个文件)查找{pattern},然后对匹配到的行 ...
- Sql Server 查询第30条数据到第40条记录数
1.select top 10 * from (select top 40 * from tablename order by id desc);
- framebuff 显示子系统
#include <unistd.h> #include <stdio.h> #include <fcntl.h> #include <linux/fb.h ...
- ZOJ3772_Calculate the Function
给出一些数组a[i],每次询问为li,ri,定义f[li]=a[li],f[li+1]=a[li+1],对于其他不超过ri的位置,f[x]=f[x-1]+a[x]*f[x-2] . 题目有着浓浓的矩阵 ...
- 在NopCommerce中启用MiniProfiler
MVC MiniProfiler是Stack Overflow团队设计的一款对ASP.NET MVC.WebForm 以及WCF 的性能分析的小程序.可以对一个页面本身,及该页面通过直接引用.Ajax ...
- git -- 如何解决冲突
遇到冲突,首先要编辑冲突文件,可以使用vim或者其他工具,冲突文件变现为: <<<<HEAD 到 ==== :代表本地分支的修改内容 ==== 到 >>>&g ...
- Robot Framework-工具简介及入门使用
Robot Framework-Mac版本安装 Robot Framework-Windows版本安装 Robot Framework-工具简介及入门使用 Robot Framework-Databa ...
- Android之Inflate()方法用途
转自:http://blog.csdn.net/andypan1314/article/details/6715928 Inflate()作用就是将xml定义的一个布局找出来,但仅仅是找出来而且隐藏的 ...
- BZOJ3175 Tjoi2013 攻击装置(二分图匹配)
传送门 Description 给定一个01矩阵,其中你可以在0的位置放置攻击装置.每一个攻击装置(x,y)都可以按照"日"字攻击其周围的 8个位置(x-1,y-2),(x-2,y ...