Leetcode 342. Power of Four (Easy) (cpp)
2016-07-21 18:18
106 查看
Leetcode 342. Power of Four (Easy) (cpp)
Tag: Bit Manipulation
Difficulty: Easy
Tag: Bit Manipulation
Difficulty: Easy
/* 342. Power of Four (Easy) 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? */ class Solution { public: bool isPowerOfFour(int num) { return num > 0 && !(num & (num - 1)) && (num & 0x55555555) == num; } };
相关文章推荐
- poj2632 Crashing Robots
- PAT乙级1001. 害死人不偿命的(3n+1)猜想 (15) C++
- c语言的一些语句说明和查找问题
- [算法学习笔记]冒泡排序和选择排序
- c++学习笔记(十一):C++类的访问修饰符
- Windows下php扩展开发c++动态库
- C++--单例模式样板
- 高质量C和C++编程 读书笔记 (第一二章)
- C/C++面试题:static(静态)变量的作用
- C语言求矩阵偶数的平均值和程序输出某数的问题
- 《深度探索C++对象模型》2
- C++ STL Adaptor stack、queue和vector的使用
- win7 c/c++ opencv 开发环境搭建
- struct_list_sign_my_name.c
- 【华为OJ平台练习题】求最后一个单词长度
- 一个关于 字符与字符串 的 小问题
- a small test for array
- c++学习笔记(十):C++类和对象
- C语言中运算符优先级记忆方法
- malloc底层实现