326. Power of Three

Given an integer, write a function to determine if it is a power of three.

Follow up:

Could you do it without using any loop / recursion?

思路:看这个数取以3为底的对数结果是否为整数,C++中只有自然对数函数log()和以10为底的对数函数log10(),所以要借助换底公式。此处用自然对数会有精度问题,用以10为底的对数则没有这个问题。

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

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

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

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

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

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

  7. Leetcode 326 Power of Three 数论

    判断一个数是否是3的n次幂 这里我用了一点巧,所有的int范围的3的n次幂是int范围最大的3的n次幂数(即3^((int)log3(MAXINT)) =  1162261467)的约数 这种方法是我 ...

  8. [LeetCode] 326. Power of Three + 342. Power of Four

    这两题我放在一起说是因为思路一模一样,没什么值得研究的.思路都是用对数去判断. /** * @param {number} n * @return {boolean} */ var isPowerOf ...

  9. [LeetCode] 231. Power of Two 2的次方数

    Given an integer, write a function to determine if it is a power of two. Example 1: Input: 1 Output: ...

随机推荐

  1. ClistCtrl用法及总结(由怎样隐藏ListCtrl列表头的排序小三角形这个bug学习到的知识)

    1 怎样隐藏ListCtrl列表头的排序小三角形 在创建控件是加入|LVS_NOSORTHEADER风格即可. 一下是用法总结: 本文根据本人在项目中的应用,来谈谈CListCtrl的部分用法及技巧. ...

  2. Qt开发陷阱一QSTACKWIDGET

    原始日期:2015-10-14 00:55 1.使用QStackWidget控件的setCurrentIndex方法时,要注意参数0对应着ui上StackWidget的page1,而不是page0,没 ...

  3. android网页分享到朋友圈问题求助?

    目前想要实现通过QQ将网页分享到微信好友或朋友圈,看见有些APP是直接分享出去左下角图标显示的是QQ.求助各位大牛提供下思路. 这种功能是怎么实现的.应该不是通过android的系统分享实现的吧?.查 ...

  4. Oracle数据库概念和一些基本的SQL语句

    1.数据 定义:描述事物的符号.例如:文本.音频.视频都是数据. 2.数据库 存放数据的仓库,存放在计算机中,按照一定格式存放,可以为用户共享. 3.数据库的发展阶段 1.网状数据库 2.层次数据库 ...

  5. ASP.NET MVC 重写RazorViewEngine实现多主题切换

    在ASP.NET MVC中来实现主题的切换一般有两种方式,一种是通过切换皮肤的css和js引用,一种就是通过重写试图引擎.通过重写试图引擎的方式更加灵活,因为我不仅可以在不同主题下面布局和样式不一样, ...

  6. [leetcode-535-Encode and Decode TinyURL]

    TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/desi ...

  7. RunTime 运行时

    简单介绍RunTime 运行时的用法 以下操作都需要导入头文件 #import <objc/message.h> #pragma mark -- 发消息 //OC方法调用的本质就是让对象发 ...

  8. jzoj3760. 【BJOI2014】Euler

    题目大意: 欧拉函数  φ(n)  定义为不超过正整数 n 并且与 n 互素的整数的数目. 可以证明 φ(n) =  n ∗ ∏ (1 − 1 / pi). 其中 pi(1 <= i <= ...

  9. H3CNE实验:通过Console端口本地访问H3C设备

    连接好Console线后,将交换机开机,在SecureCRT上会显示如下信息: Starting...... RAMLine.....OK System is booting............. ...

  10. Building Apps for Windows 10 on LattePanda–Jump Start

    1.引言 目前来看,LattePanda应该是最小的运行Full Windows 10系统的开发板了(注意,不是Windows 10 for Mobile,也不是Windows 10 IoT系列,而是 ...