O(1)时间检测2的幂次-LintCode
来源:互联网 发布:python 写shell脚本 编辑:程序博客网 时间:2024/05/27 00:32
用 O(1) 时间检测整数 n 是否是 2 的幂次。
样例
n=4,返回 true;
n=5,返回 false.
挑战
O(1) time
#ifndef C142_H#define C142_H#include<iostream>using namespace std;class Solution {public: /* * @param n: An integer * @return: True or false */ bool checkPowerOf2(int n) { // write your code here if (n == 1) return true; if (n <= 0) return false; if (n % 2 != 0) return false; else { if (checkPowerOf2(n >> 1)) return true; } }};#endif
阅读全文
0 0
- LintCode 142. O(1)时间检测2的幂次
- LintCode:O(1)时间检测2的幂次
- LintCode :O(1)时间检测2的幂次
- O(1)时间检测2的幂次-LintCode
- 2的次方(去哪儿2017校招真题) & O(1)时间检测2的幂次(LintCode)
- lintcode-O(1)检测2的幂次-142
- LintCode-O(1)检测2的幂次
- LintCode O(1)检测2的幂次
- LintCode O(1) Check Power of 2 O(1)检测2的幂次
- O(1)时间检测2的幂次
- O(1)时间检测2的幂次
- Java实现-O(1)时间检测2的幂次
- O(1)时间检测2的幂次
- O(1)检测2的幂次
- O次(1)检测2的幂
- 用 O(1) 时间检测整数 n 是否是 2 的幂次。
- 比特位操作——O(1)时间检测2的幂次
- 142.O(1) Check Power of 2-O(1)时间检测2的幂次(容易题)
- 【PHP基础知识】——cookie与session的区别
- 常用前端社会分享code
- Windows Update无法检查更新
- php composer 学习记录
- linux- dns和ddns服务
- O(1)时间检测2的幂次-LintCode
- Linux文件IO-open,write,read,lseek,close
- Bentley AutoPLANT Plant Design XM 08.09.03.30 _USB 完整好用版)\
- 下载的文件没有文件类型
- 树莓派TF卡低格,存储空间还原
- Maya常用工具添加自定义方法
- Easyui dialog对话框遮挡关闭按钮问题的解决
- 使用HttpURLConnection从网上获取一张图片
- Skipped 'upload/index' -- Node remains in conflict At revision 37004