Leetcode 342 Power of Four 数论
题意:判断一个数是不是4的幂数,和Power of two类似。
先判断num是否大于0,再判断num是否能开根号,最后判断num开根号后的数是否是2^15的约数。
提示:4的幂数开根号就是2的幂数。
注意:判断一个双精度数a是否是0,请用fabs(a)<一个极小的数,如本题中用的是1e-9。
class Solution {
public:
bool isPowerOfFour(int num) {
return (num > ) && (fabs((int)sqrt(num) -sqrt(num)) <1e- ) && ((<<) % ((int)sqrt(num)) == );
}
};
Leetcode 342 Power of Four 数论的更多相关文章
- [LeetCode] 342. Power of Four 4的次方数
Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example:Giv ...
- LeetCode 342. Power of Four (4的次方)
Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example:Giv ...
- LeetCode 342. Power of Four
Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example:Giv ...
- Leetcode 231 Power of Two 数论
同样是判断数是否是2的n次幂,同 Power of three class Solution { public: bool isPowerOfTwo(int n) { ) && ((( ...
- Python [Leetcode 342]Power of Four
题目描述: Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Examp ...
- [LeetCode] 342. Power of Four(位操作)
传送门 Description Given an integer (signed 32 bits), write a function to check whether it is a power o ...
- Leetcode 326 Power of Three 数论
判断一个数是否是3的n次幂 这里我用了一点巧,所有的int范围的3的n次幂是int范围最大的3的n次幂数(即3^((int)log3(MAXINT)) = 1162261467)的约数 这种方法是我 ...
- [LeetCode] 231 Power of Two && 326 Power of Three && 342 Power of Four
这三道题目都是一个意思,就是判断一个数是否为2/3/4的幂,这几道题里面有通用的方法,也有各自的方法,我会分别讨论讨论. 原题地址:231 Power of Two:https://leetcode. ...
- 231. Power of Two 342. Power of Four -- 判断是否为2、4的整数次幂
231. Power of Two Given an integer, write a function to determine if it is a power of two. class Sol ...
随机推荐
- CSS线性渐变
/*CSS线性渐变*/ FILTER: progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr=#ffffff, ...
- [转][MSSQL]SQL Server 2008 记住密码功能
本文转自:http://zhidao.baidu.com/link?url=V_laNOvutMin0kU3DUaMhLSFAYfgtz2IoEAjh8grNVPOZLpd8Pudb4iqZl88Tn ...
- 最近在研究备份和虚拟磁带库(LEGATO + MHVTL + SCST + LanFree)
最近在研究备份和虚拟磁带库(LEGATO + MHVTL + SCST + LanFree) 有些小成功,MHVTL已经搞定,SCST + LANFREE 正在继续实验中,接着就是LEGATO. 最终 ...
- [z]vs中无法加入断点进行调试的解决方案
http://blog.chinaunix.net/uid-15464162-id-3799069.html [ 1] 以前也遇到过同样的问题,但没有问个为什么,也没有探个毕竟.昨天调试一个DLL,添 ...
- SQL Server 【CTE + FOR XML PATH】使用笔记~
CREATE FUNCTION [dbo].[Getxxxxxxxxx] ( @productCategoryId INT, @SplitChar varchar ) RETURNS NVARCHAR ...
- LeetCode340 Longest Substring with At Most K Distinct Characters
This is a question needs pay for , I have no money to pay ,so just write some test case by myself. I ...
- Python学习第八天(os)
os主要是实现文件夹的创建和管理功能 os.mkdir(path) 创建目录 os.chdir(path)改变当前工作目录 os.fchdir() 通过文件描述符改变工作目录 os.chroot() ...
- 30、准确计算CoreText高度的方法
http://ios-iphone.diandian.com/post/2012-03-29/18389515 - (int)getAttributedStringHeightWithString:( ...
- 修改ubuntu DNS的步骤(图文)
有时候连接上VPN服务器后,还是打不开某些网站,这时候,需要对DNS进行更改,一般是修改成为谷歌提供的免费DNS:8.8.8.8 8.8.4.4,在windows下更改比较简单(点击查看“连接上VP ...
- 解决ubuntu bash: cd: ~:Permission denied
cd /usr/local/hadoop 报错:bash: cd: /usr/local/hadoop:Permission denied 输入指令: /usr/local/hadoop 原因是没有权 ...