leetcode:bits:Power of Four(342)
2016-09-01 14:51
337 查看
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?
http://www.cnblogs.com/grandyang/p/5403783.html
Example:
Given num = 16, return true. Given num = 5, return false.
Follow up: Could you solve it without loops/recursion?
http://www.cnblogs.com/grandyang/p/5403783.html
class Solution { public: bool isPowerOfFour(int num) { while (num && (num % 4 == 0)) { num /= 4; } return num == 1; } };
相关文章推荐
- LeetCode191 Number of 1 Bits. LeetCode231 Power of Two. LeetCode342 Power of Four
- LeetCode 第 342 题(Power of Four)
- Python [Leetcode 342]Power of Four
- leetcode 342 Power of four
- LeetCode之342,Power of Four
- LeetCode - 231/326/342 - Power of Two/Three/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(java)
- 【LeetCode-342】Power of Four
- Leetcode 342 Power of Four
- LeetCode 第 342 题(Power of Four)
- LeetCode 342 Power of Four (位运算)
- LeetCode 231,326,342 --Power of Two & Three & Four
- LeetCode 342 Power of Four
- 【LeetCode-342】 Power of Four(C++)
- LeetCode 342 Power of Four