[leetcode] Power of Two
2015-07-14 14:24
218 查看
From :https://leetcode.com/problems/power-of-two/
Given an integer, write a function to determine if it is a power of two.
Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.
Hide Tags
Math Bit
Manipulation
Hide Similar Problems
(E) Number of 1 Bits
Solution :
Given an integer, write a function to determine if it is a power of two.
Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.
Hide Tags
Math Bit
Manipulation
Hide Similar Problems
(E) Number of 1 Bits
Solution :
class Solution { public: bool isPowerOfTwo(int n) { if(n <= 0) return false; long long k=1; while(k<n) { k = k<<1; } return n==k; } };
相关文章推荐
- Java 接口常量反模式及如何定义 Java 常量
- hive array、map、struct使用
- 一、树形dp(3)重建道路
- 集中化运维管理——Puppet管理之路
- 通过sql做数据透视表,数据库表行列转换(pivot和Unpivot用法)(一)
- 触发器应用 trigger
- html5 webApp常用Meta标签
- MySql时间戳的问题。
- apache-nutch-1.10 安装笔记
- Java WebService 简单实例
- 通过反编译字节码来理解 Java 枚举
- Kettle变量和自定义java代码的实例应用
- mysql的备份脚本
- 4.c语言的进制转换
- mumu血压计母亲节“拼团”盛大开幕,百度和厂家创造一个双赢的局面
- Fresco 获得Bitmap
- UI1_UITableViewHomeWork
- 程序员资源导航
- 另一种拼接数据方法,利用数组的传引用做的。
- 正则表达式--常用