判断一个数是否是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 数论的更多相关文章

  1. leetcode 326. Power of Three(不用循环或递归)

    leetcode 326. Power of Three(不用循环或递归) Given an integer, write a function to determine if it is a pow ...

  2. 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 ...

  3. [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 ...

  4. 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 ...

  5. Leetcode 342 Power of Four 数论

    题意:判断一个数是不是4的幂数,和Power of two类似. 先判断num是否大于0,再判断num是否能开根号,最后判断num开根号后的数是否是2^15的约数. 提示:4的幂数开根号就是2的幂数. ...

  6. Leetcode 231 Power of Two 数论

    同样是判断数是否是2的n次幂,同 Power of three class Solution { public: bool isPowerOfTwo(int n) { ) && ((( ...

  7. 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 ...

  8. LeetCode 326 Power of Three(3的幂)(递归、Log函数)

    翻译 给定一个整型数,写一个函数决定它是否是3的幂(翻译可能不太合适-- 跟进: 你能否够不用不论什么循环或递归来完毕. 原文 Given an integer, write a function t ...

  9. 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 ...

随机推荐

  1. 小甲鱼python视频第九讲(课后习题)

    1.列表里可以存放什么东西? 可以存放任何的数据类型, list1 = ['我爱你','i love you',1314] print(list1) 2.向列表中添加元素 append(将参数作为一个 ...

  2. geohash算法原理及实现方式

    1.geohash特点 2.geohash原理 3.geohash的php .python.java.C#实现代码 4.观点讨论 w微博:http://weibo.com/dxl0321 geohas ...

  3. sqlite query用法

    本文转自http://blog.csdn.net/double2hao/article/details/50281273,在此感谢作者 query(table, columns, selection, ...

  4. 【erlang】IPv6格式转IPv4

    erlang里面的httpd模块保存的http请求头里面,其中remote_addr 保存的是IPv6的格式. 即使是IPv4,也会用IPv6的格式来保存.如 {remote_addr, " ...

  5. 前端利器:SASS基础与Compass入门

    SASS是Syntactically Awesome Stylesheete Sass的缩写,它是css的一个开发工具,提供了很多便利和简单的语法,让css看起来更像是一门语言,这种特性也被称为“cs ...

  6. homework 15 2016 6 2 模板

    #include<iostream>#include<cmath>#include<cstdio> using namespace std; template &l ...

  7. C# IEnumerable,Lambda表达式和 Parallel并行编程的用法

    以前一直主要做C++和C方面的项目,对C#不太了解熟悉,但听说不难,也就一直没有在意学习C#方面的知识.今天有个C#项目,需要做些应用的扩展,同时修改一些bug.但看了C#代码,顿时觉得有些不适应了. ...

  8. [Leetcode][JAVA] Valid Palindrome

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  9. Android--Notification

    1.通知(Notification)是应用程序没有运行在前台时可以向用户发出一些提示消息的功能,发出通知后,手机状态栏会显示通知,用户可以通过下拉状态栏来查看和操作通知: 2.Notification ...

  10. (原创)defparam的应用(Verilog,CPLD/FPGA)

    1.Abstract     在同一个模块被多次例化的时候,改变参数构建不同的硬件实体是一个很好的选择.特别是今天帮一个朋友调试一个比较复杂的逻辑,深有体会.这个也是一个小技巧,回来也查了许多资料,强 ...