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 ...
随机推荐
- 让XCode的Stack Trace信息可读
程序报错信息如下:
- 魅族 -- 禁止D及以下级别LOG的输出
真机调试时:Log.d()打印不出信息,模拟器可以. 使用的手机:魅族. 状况:禁止D及以下级别LOG的输出. PS.Log.d("h_bl", "进入执行") ...
- 继续推荐几款VisualStudio的插件(二)
今天晚上闲着的时候逛了一下,发现了几款不错的VisualStudio插件,这里推荐一下: Exception Breaker 在调试的时候,为了及时发现错误,我们常常会打开"总是引发所有CL ...
- SQL Server 存储过程小结
Transact-SQL中的存储过程,非常类似于Java语言中的方法,它可以重复调用.当存储过程执行一次后,可以将语句缓存中,这样下次执行的时候直接使用缓存中的语句.这样就可以提高存储过程的性能. Ø ...
- iOS:自定义代码块{ }
1.Xcode本身带有编码常用的代码块可供使用,如下图 调用方法: (1)直接拖到代码区域中: (2)使用快捷键,键入 “while”, Xcode就会出现自动完成的提示 也可以自定义自己常用的代码块 ...
- Python测试Kafka集群(kafka-python)
生产者代码: import time from kafka import SimpleProducer, KafkaClient from kafka import KafkaProducer pro ...
- html DOM 的继承关系
零散的知识聚合在一起,就会形成力量,就有了生命力. 如各种语言的开发框架, 都是右各个碎片化的功能聚合在一起,构成有机地整体,便有了强大的力量.will be powerful! 如: jquery ...
- HDU 4287-Intelligent IME(哈希)
Intelligent IME Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4008 Parent and son LCA+树形dp
题意: 给定case数 给定n个点的树,m个询问 以下n-1行给出树边 m个询问 x y 问:以x为根.y子树下 y的最小点标的儿子节点 和子孙节点 思路: 用son[u][0] 表示u的最小儿子 s ...
- python——数据结构之单链表的实现
链表的定义: 链表(linked list)是由一组被称为结点的数据元素组成的数据结构,每个结点都包含结点本身的信息和指向下一个结点的地址.由于每个结点都包含了可以链接起来的地址 信息,所以用一个变量 ...