[LeetCode]342. Power of Four
来源:互联网 发布:淘宝内衣买家秀贴吧 编辑:程序博客网 时间:2024/05/17 00:53
[LeetCode]342. Power of Four
题目描述
思路
位操作
4的幂次数的特点
写成二进制后只有一位为1,所以需要检测二进制数中1的位数
同时满足这条性质的有2^n(n > 0)的幂次,所以还需要检测是否为4的幂次
特点 4的幂次数 - 1 可以被三整除
代码
class Solution {public: bool isPowerOfFour(int n) { return n > 0 && (n & (n - 1)) == 0 && (n - 1) % 3 == 0; }};
0 0
- 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
- LeetCode 342. Power of Four
- [leetcode] 342. Power of Four
- PagerAdapter中的NotifyDataSetChanged
- 关于微信APP支付,提示支付验证签名失败
- autoresizing布局
- 二叉树常用操作算法集、解释及注意事项
- linux删除大量文件
- [LeetCode]342. Power of Four
- MATLAB读json文件
- 致青春
- 安卓组件化架构实践
- day19_filter
- Linux学习笔记10
- ubuntu c/c++ 版本检测程序
- FontIcon -- Web开发的新选择
- 小学数学 oj