142. O(1) Check Power of 2【easy】
142. O(1) Check Power of 2【easy】
Using O(1) time to check whether an integer n is a power of 2
.
For n=4
, return true
;
For n=5
, return false
;
O(1) time
解法一:
class Solution {
public:
/*
* @param n: An integer
* @return: True or false
*/
bool checkPowerOf2(int n) {
if (n > && (n & n - ) == ) {
return true;
} return false;
}
};
142. O(1) Check Power of 2【easy】的更多相关文章
- 142. O(1) Check Power of 2【LintCode by java】
Description Using O(1) time to check whether an integer n is a power of 2. Example For n=4, return t ...
- 142. Linked List Cycle II【easy】
142. Linked List Cycle II[easy] Given a linked list, return the node where the cycle begins. If ther ...
- 160. Intersection of Two Linked Lists【easy】
160. Intersection of Two Linked Lists[easy] Write a program to find the node at which the intersecti ...
- 234. Palindrome Linked List【easy】
234. Palindrome Linked List[easy] Given a singly linked list, determine if it is a palindrome. Follo ...
- 27. Remove Element【easy】
27. Remove Element[easy] Given an array and a value, remove all instances of that value in place and ...
- 459. Repeated Substring Pattern【easy】
459. Repeated Substring Pattern[easy] Given a non-empty string check if it can be constructed by tak ...
- 170. Two Sum III - Data structure design【easy】
170. Two Sum III - Data structure design[easy] Design and implement a TwoSum class. It should suppor ...
- 206. Reverse Linked List【easy】
206. Reverse Linked List[easy] Reverse a singly linked list. Hint: A linked list can be reversed eit ...
- 203. Remove Linked List Elements【easy】
203. Remove Linked List Elements[easy] Remove all elements from a linked list of integers that have ...
随机推荐
- javolution-core-java-6.1.0.jar 的使用
官方网址:http://javolution.org/apidocs/javolution/io/Struct.html 第一步:导包 第二步:创建继承的结构体 结构体定义如下所示: public c ...
- SQL Server Latch Classes Library
https://www.sqlskills.com/help/latches/ (Companion SQL Server Wait Types Library) This site lists al ...
- winform 窗体实现增删改查(CRUD)窗体基类模式
参考博客下方:http://www.cnblogs.com/wuhuacong/archive/2010/05/31/1748579.html 对于一般常用到的编辑数据.新增数据窗体,分开了两个不同的 ...
- Swift,字典
1.创建(Dictionary)字典(无序的可重复) (1)指定类型 var a:Dictionary<String,String>=["a":"b" ...
- 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:3.安装Oracle RAC-3.2.安装 cvuqdisk 软件包
3.2.安装 cvuqdisk 软件包 3.2.1. 准备Oracle Grid安装包 上传Grid .Oracle 安装文件: sftp> put E:\Software\linux.x64 ...
- Dell服务器Raid卡电池策略调整
DELL服务器的Riad卡都有可充电池的特性,这块可充电电池,在不使用时,也会有微弱的放电现象,当它的电量放电到低到一定程度时,Raid卡控制器就会对电池进行一次“放电”,将剩余的电量放掉,然后再进行 ...
- WebGL可视化地球和地图引擎:Cesium.js
http://www.open-open.com/lib/view/open1427341416418.html Cesium 是一个JavaScript 库用于在Web浏览器创建 3D 地球和 ...
- spring+mybatis项目启动报错Initializing Spring root WebApplicationContext
这个问题很怪异,各种各样的情况都会导致这个问题的出现,主要是由于sping加载读取配置文件的时候出了问题.我在处理mybatis的时候出现了这个问题,后来排查发现,在mybatis的配置文件中如果有大 ...
- http://www.cnblogs.com/monian/p/3822980.html
http://www.cnblogs.com/monian/p/3822980.html
- 【枚举】【SDOI 2011】【bzoj 2241】打地鼠
2241: [SDOI2011]打地鼠 Time Limit: 10 Sec Memory Limit: 512 MB Submit: 877 Solved: 557 Description 打地鼠是 ...