每天一道LeetCode--342. Power of Four
Given an integer (signed 32 bits), write a function to check whether it is a power of 4.
Example:
Given num = 16, return true. Given num = 5, return false.
Follow up: Could you solve it without loops/recursion?
public class Solution {
public boolean isPowerOfFour(int num) {
int n=num;
while(n>0&&n%4==0){
n/=4;
}
return n==1;
//return (num > 0) && ((num & (num - 1)) == 0) && ((num & 0x55555555) == 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 342 Power of Four 数论
题意:判断一个数是不是4的幂数,和Power of two类似. 先判断num是否大于0,再判断num是否能开根号,最后判断num开根号后的数是否是2^15的约数. 提示:4的幂数开根号就是2的幂数. ...
- 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】#342. Power of Four
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- [LeetCode] 231 Power of Two && 326 Power of Three && 342 Power of Four
这三道题目都是一个意思,就是判断一个数是否为2/3/4的幂,这几道题里面有通用的方法,也有各自的方法,我会分别讨论讨论. 原题地址:231 Power of Two:https://leetcode. ...
- 【一天一道LeetCode】#231. Power of Two
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- 【一天一道LeetCode】#326. Power of Three
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
随机推荐
- windows下实现微秒级的延时
windowsintegeriostream汇编嵌入式任务 最近正在做一个嵌入式系统,是基于windows ce的,外接硬件的时序要微秒级的延时.1.微秒级的延时肯定不能基于消息(SetTimer函数 ...
- 使用SVG Path绘图
最近一个项目,需要做个Web版本的设计器,用来进行工厂流水线布局的设计. 项目中采用了SVG.JS来做,但是以前流水线是采用单纯的画线的方式实现.客户提出希望用不同的底纹表示不同的流水线,经过一番调查 ...
- JQuery ajax请求一直返回Error(parsererror)
$.ajax({ type :"post", url :"busine_in.action", timeout : 40000, data: "cen ...
- 教你看懂邮件头信息<转载>
MIME对于邮件系统的扩展是巨大的,因为在MIME出现以前,信件内容如果要包括声音和动画,就必须把它变为ASCII码或把二进制的信息变成可以传送的编码标准,而接收方必须经过解码才可以获得声音和图画信息 ...
- PyQt入门系列(一):Hello World
开始搞PyQt了,顺便记录一下自己的学习!资料参考某大神的PyQt4 精彩实例分析,以及<征服Python>这本书. 下面是Demo: #-*- coding:utf-8 -*- #编码声 ...
- Linux设备模型分析之kset(基于3.10.1内核)
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 内核版本:3.10.1 一.kset结构定义 kset结构体定义在include/linux/kobject.h ...
- Android编译提示ImportError: No module named bz2的解决办法
在安装node.js时提示ImportError: No module named bz2.很明显这个python中没有装bz2的库导致的.解决方法:sudo apt-get install libb ...
- [MODx] 3. Working with chunks, TV, Category
1. Add chunk: For example, replace the header by using chunk. Usage: [[$chunk_name]] Cut all the hea ...
- PAT 1003
1003. Emergency (25) As an emergency rescue team leader of a city, you are given a special map of yo ...
- php技术概要汇总
php搜索-> sphinx coreseek : 中文分词.中文搜索 samba :把linux服务器端目录映射的本地. 视频截图插件.音频视频转换(ffmpeg): 1)w ...