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 ...
随机推荐
- 用nodej和glub-watcher写的监听go 项目自动编译,很鸡肋
glub 一般都是很轻量的编译. go太重了,改一小个部分,就编译的话,多数是编译失败. 而且很消耗性能,还没想到完美的优化办法. 暂时用个定时器 监听2秒,停止1秒,如此循环,会减少些 “无效”的编 ...
- 浪潮不能进bios解决过程
开机时会有个提示一闪而过,经过拍摄视频观看发现是"Press DEL to SETUP or TAP to post" 但是,反复重启不停按Delete键都无效,都进入了Ctrl+ ...
- 访问https链接方法
<a id='___szfw_logo___' href='https://credit.szfw.org/CX20160808028375110138.html' target='_blank ...
- vb.net下载代码
'后台 Partial Public Class Download2 Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender ...
- mysql 全文搜索的FULLTEXT
FULLTEXT索引 创建FULLTEXT索引语法 创建table的时候创建fullText索引 CREATE TABLE table_name( column1 data_type, column2 ...
- VMware12 安装 CentOS 6.5 64位
前言:本人在配置Hadoop的过程中,需要搭建Cent OS 64 环境,借此,顺便将Cent OS 64 的安装在此记录,方便自己,也方便大家学习.本次是在VM12虚拟机中实现Cent OS 64 ...
- VM - Bridge Adapter
如何让外部可以连到本地的虚拟机. 1. 网络模式 - Bridged Adapter 2. 确保本机插上网线 3. 如果虚拟机是 Windows 8.1, 需要开启如下选项.
- font-face跨域办法
font-face是现在比较流行的技术,可以矢量化你的图标,更改颜色方便等等.如果你想更进一步了解他,请点击这里(CSS3 icon font完全指南)今晚有网友问到font-face跨域在nginx ...
- 「2013-9-5」Configure WingIDE for better display of East Asian Glyphs
很久没写软件配置相关的博客了.这次对于 WingIDE 在 Windows 下的字体配置,折腾了好一阵子,略曲折,也反映了「不清楚原理和背景的情况下,盲人摸象的效率低下是必然」这条放之四海而皆准的赤果 ...
- log4net Tutorial
Introduction One of the greatest logging tools out there for .NET is log4net. This software is the g ...