LeetCode之342,Power of Four
来源:互联网 发布:java嵌入html5 编辑:程序博客网 时间:2024/06/06 02:11
这个题和Power Of Two有很多相同点,可以在其基础上做适当延伸。
原题:
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?
特别注意上面那个:follow up的内容。
解决用的代码是:
class Solution {public: bool isPowerOfFour(int num) { //if 2 or 8,return false //if 4 or 16,return true //so 0101 & 1000 =0000 //0101 & 0100 =0100 //get idea above,so if(num<=0) return false; return ((num&(num-1))==0 &&(num&0x55555555)); }};
0 0
- LeetCode之342,Power of Four
- leetcode之Power of Four
- (LeetCode 342) Power of Four
- 【LeetCode-342】Power of Four
- Power of Four leetcode 342
- Leetcode Power of Four 342
- LeetCode 342 Power of Four
- leetcode 342 Power of four
- leetcode 342 Power of Four
- LeetCode[342] Power of Four
- LeetCode 342 Power of Four
- LeetCode 342 Power of Four
- Leetcode 342 Power of Four
- leetcode-342-Power of Four
- Leetcode 342 Power of Four
- [LeetCode]Power of Four
- Power of Four-Leetcode
- LeetCode Power of Four
- 直接读取raw文件下的视频文件并播放
- javascript基础:navigator对象、location对象
- window中的tls1.0、tls1.1、tls1.2启用方法!
- iOS下html上传图片被旋转问题
- XMind安装/注册完整教程
- LeetCode之342,Power of Four
- java学习
- java基础学习总结——数组
- 微信小程序:开发之前要知道的三件事
- JAVA 线程池的使用
- 【寒假任务】 洛谷1223 排队接水
- 解决springMVC4下使用@ResponseBody的中文乱码问题
- zTree的模糊搜索
- GNU工具链安装