leetcode 342. Power of Four 4的幂指数
来源:互联网 发布:java中&和&&的区别 编辑:程序博客网 时间:2024/04/30 15:39
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?
最直接的方法就是使用log函数去做判断,后来网上发现一个使用位计算的方法,直接看代码吧!
建议和这一道题leetcode 326. Power of Three 3的幂指数 一起学习。
代码如下:
public class Solution { public boolean isPowerOfFourByLog(int num) { double res=Math.log10(num) / Math.log10(4); return (res-(int)(res))==0?true:false; } public boolean isPowerOfFour(int num) { if(num<=0) return false; return (num&(num-1))==0 && (num&0x55555555)==num; }}
阅读全文
0 0
- leetcode 342. Power of Four 4的幂指数
- Power of Four | leetcode 四的幂
- 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
- 342.[leetcode]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
- 学生管理系统-----管理和设计的认识
- 解决jsp中时间戳/Long类型数据转换成日期类型问题
- Docker Commands
- CodeForces GYM 101158D Hidden Anagrams hash+unordered_set
- 深入理解计算机系统:C语言文件的链接原理
- leetcode 342. Power of Four 4的幂指数
- CNN--结构上的思考
- 树莓派 使用摄像头 Qt5 Qcamera调用提示:missing camera
- poj1112 Team Them Up!(二分图染色+dp)
- 洛谷P2380狗哥采矿,动态规划例题讲解
- poj 1741 Tree 树的点分治
- SQL SERVER 获取数据库中所有的表名及表中的数据量/查看每个数据库的链接打开数量
- python3 Note I
- 携带Cookie登入