leetcode 342. Power of Four 解题报告
来源:互联网 发布:coc防空火箭升级数据 编辑:程序博客网 时间:2024/05/16 16:19
原题链接
解题思路
刚开始题目理解错了,不过仔细审题后轻松解决
- 首先把特殊数字处理了,即非正数和1
- 将要处理的数字num & (num-1)。这样可以得出其总共有几个1(二进制)
- 若只有最高位为1,那再判断其二进制0的总个数是否是2的倍数。(4的二进制是两个0)。
- 得出答案。
解题代码
public class Solution { public boolean isPowerOfFour(int num) { if(num<=0){ return false; } if(num ==1 ) return true; int a = num & (num-1); if(a==0&&(((Integer.toBinaryString(num)).length()-1)&1)==0) return true; else return false; }}
0 0
- [leetcode] 342. Power of Four 解题报告
- leetcode 342. Power of Four 解题报告
- leetcode解题报告-342. Power of Four
- [Leetcode] 342. Power of Four 解题报告
- 【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
- 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
- 第一篇博客
- 大猫品Android[四][跑通Broadcast流程-上篇]
- 209. Minimum Size Subarray Sum
- (第5讲)单链表(带头结点和不带头结点)
- Scala入门
- leetcode 342. Power of Four 解题报告
- Java并发编程:volatile关键字解析
- 图像局部特征(一)--概述
- 软文标题技巧与模版
- 远程登录MySQL
- 最小生成树小结
- GDI双缓冲绘图
- 码农四年,年记
- 自制编译器---c++实现词法分析器