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 ...
随机推荐
- [P2396] yyy loves Maths VII
Link: P2396 传送门 Solution: 一眼能看出$O(n*2^n)$的状压$dp$ 但此题是个卡常题,$n=23/24$的时候就别想过了 这题算是提供了一种对状压$dp$的优化思路吧 原 ...
- 【二分】bzoj2083 [Poi2010]Intelligence test
v[x]记录了x值的出现位置序列. 对每个b中的元素,每次在v[b[i]]中二分. 因此要记录上一次二分到了a数组的哪个位置. #include<cstdio> #include<v ...
- 1.2(学习笔记) JSP动作元素
动作元素 jsp:useBean:根据指定类实例化一个对象,类似Preson per = new Preson(); <jsp:useBean id="对象名" class ...
- a + b ——C语言初学者百题大战之四
#include <stdio.h> int main() { int a,b; scanf("%d %d",&a,&b); printf(" ...
- linux-文件中行按照出现次数多少排序
cat sorttest | sort | uniq -c | sort -k1 sorttest内容如下:
- druid 配置监控界面和开启spring支持
1.配置监控页面 <!-- JNDI方式配置数据源 --> <!-- <bean id="dataSource" class="org.sprin ...
- 调试Ajax调用的利器firebug
这几天我在家里调试PCS的Ajax调用时候发现一个问题就是调试手段太少,一般我会在进入ajax调用前加上一段alert输出变量信息. 比如 alert($("#taskid").v ...
- 【AS3 Coder】任务四:噪音的魅力(上)
使用框架:AS3任务描述:使用AS3中BitmapData的noise方法以及perlinNoise方法构建自然景观效果以及其他一些比较cool的效果难度系数:2 本文章源码下载:www.iamsev ...
- JSON,字符串,MAP转换
package com.tree.autotest.testcase.IAuditBillDetailService; import com.alibaba.fastjson.JSON;import ...
- Pinterest架构:两年内月PV从零到百亿
Pinterest正经历了指数级曲线般的增长,每隔一个半月就翻番.在这两年里,Pinterest,从 每月PV量0增长到100亿,从两名c创始人和一个工程师成长为四十个工程师,从一台MySQL 服务器 ...