LeetCode342. Power of Four 简单解法
来源:互联网 发布:学游泳费用 知乎 编辑:程序博客网 时间:2024/06/05 06:09
题目要求:
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_new {public boolean isPowerOfFour(int num) {if(num > 0 && (num & 0x55555555) != 0 && (num & num - 1) == 0) return true;return false;}}
判断num 是否大于0;然后进行二进制奇数位的选取;最后要除去2的幂数.
1 0
- LeetCode342. Power of Four 简单解法
- LeetCode342. Power of Four
- leetcode342. Power of Four
- Power of Four问题及解法
- [LeetCode]Power of Four
- 342. Power of Four
- Power of Four-Leetcode
- LeetCode Power of Four
- LeetCode - Power of Four
- 113.Power of Four
- 342. Power of Four
- 342. Power of Four
- Power of Four
- leetcode_342 Power of Four
- LeetCode:Power of Four
- leetcode---Power of Four
- 342. Power of Four
- [LeetCode] Power of Four
- IOS 调用照相机、相册功能
- ntohs, ntohl, htons,htonl的比较和详解
- Codeforces732D Exams
- java反射学习例子
- tomcat
- LeetCode342. Power of Four 简单解法
- LINUX --- 大内核(顺序阅读一)
- yii2自定义报错页面
- 关于SharedSDK中短信注册和分享功能冲突问题的解决办法
- android 6.0运行时权限
- JDK1.5新特性--可变参数
- Struts2 in action 笔记4
- 使用react写的第一个轮播图组件
- 如何避免outlook发信,忘记标题和附件