LintCode_O(1)检测2的幂次
来源:互联网 发布:淘宝首页前端代码 编辑:程序博客网 时间:2024/05/29 17:01
问题描述:
用 O(1) 时间检测整数 n 是否是 2 的幂次。
样例:n=4
,返回 true
;n=5
,返回 false
.
注意:O(1) 时间复杂度
算法思想:最关键的判断是否2的幂次的只有一句:(n&(n-1))==0是否成立; public static boolean checkPowerOf2(int n){
boolean flag=false;
if(n>0&&(n&(n-1))==0){
flag=true;
}
return flag;
}
0 0
- LintCode_O(1)检测2的幂次
- O(1)检测2的幂次
- O次(1)检测2的幂
- 题目 :O(1)检测2的幂次
- lintcode-O(1)检测2的幂次-142
- LintCode-O(1)检测2的幂次
- LintCode O(1)检测2的幂次
- LintCode 142. O(1)时间检测2的幂次
- O(1)时间检测2的幂次
- LintCode:O(1)时间检测2的幂次
- O(1)时间检测2的幂次
- LintCode :O(1)时间检测2的幂次
- Java实现-O(1)时间检测2的幂次
- O(1)时间检测2的幂次
- O(1)时间检测2的幂次-LintCode
- LintcodeO(1)时间检测2的幂次
- 142-时间检测2的幂次
- 2的次方(去哪儿2017校招真题) & O(1)时间检测2的幂次(LintCode)
- LeetCode---Binary Tree Level Order Traversal
- JS_控制输入,只能键入数字
- Android封装SharedPreferences工具类
- 数据库实验NetMusicShop(一)
- [LeetCode] Insert Interval
- LintCode_O(1)检测2的幂次
- Android开发工程师必看面试题:(一)
- OOP 多态和构造器执行顺序
- 数据库实验NetMusicShop(二)
- css3选择器
- 使用NSUserDefault存储数据
- Android 总结
- AOJ 0118
- android 使用Shape绘制实用圆圈