142. O(1) Check Power of 2【easy】

Using O(1) time to check whether an integer n is a power of 2.

Have you met this question in a real interview?

Yes
Example

For n=4, return true;

For n=5, return false;

Challenge

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】的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 234. Palindrome Linked List【easy】

    234. Palindrome Linked List[easy] Given a singly linked list, determine if it is a palindrome. Follo ...

  5. 27. Remove Element【easy】

    27. Remove Element[easy] Given an array and a value, remove all instances of that value in place and ...

  6. 459. Repeated Substring Pattern【easy】

    459. Repeated Substring Pattern[easy] Given a non-empty string check if it can be constructed by tak ...

  7. 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 ...

  8. 206. Reverse Linked List【easy】

    206. Reverse Linked List[easy] Reverse a singly linked list. Hint: A linked list can be reversed eit ...

  9. 203. Remove Linked List Elements【easy】

    203. Remove Linked List Elements[easy] Remove all elements from a linked list of integers that have ...

随机推荐

  1. SD 一轮集训 day1 lose

    神TM有是结论题,我讨厌结论题mmp. 杨氏矩阵了解一下(建议去维基百科). 反正就是推柿子,使劲推,最后写起来有一点小麻烦,但是在草稿纸(然鹅我木有啊)上思路清晰的话还是没问题的. #include ...

  2. Java学习笔记(4)

    控制流程语句之---------switch选择判断语句 switch(你的选择) case 值1: 符合条件执行的语句: break: case 值2: 符合条件执行的语句: break: case ...

  3. Python 升级3.6

    首先:更新gcc,因为gcc版本太老会导致新版本python包编译不成功代码如下:#yum -y install gcc 然后下载python源tar包 可利用linux自带下载工具wget下载,如下 ...

  4. vb6 wininet

    Private Const UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; .NET CLR 1.1.4322)&qu ...

  5. [转] matlab调用opencv函数的配置

    原文地址百度账户 aleasa123 方式1 1.  首先保证vs2010能正确调用opencv函数, 2.  Matlab中选择编译器,操作如下: 打开matlab2012,输入mex –setup ...

  6. 【mybatis】mybatis使用java实体中定义的常量,或静态方法

    mybatis使用java实体中定义的常量 示例代码: <select id="findDealerInfo" parameterType="com.pisen.c ...

  7. C++11的初始化列表

      初始化是一个非常重要的语言特性,最常见的就是对对象进行初始化.在传统 C++ 中,不同的对象有着不同的初始化方法,例如普通数组.POD (plain old data,没有构造.析构和虚函数的类或 ...

  8. Linux下使用GDB进行调试

    Linux下使用GDB进行调试的常用命令记于此. $ sudo su # g++ -g test.cpp -o test -pthread # gdb test         <------- ...

  9. fedora25 采用二进制包安装mysql5.5.49

    #添加用户和组 groupadd mysql useradd -s /sbin/nologin -g mysql -M mysql /etc/passwd id mysql #安装依赖包 [root@ ...

  10. linux驱动摸索 --驱动框架初始化(结合韦东山视频教程)

    一.驱动框架 初始化:insmod 加载 1.确定主设备号: 分为静态和动态分配,其中LED_GPIO_SIZE 表示支持的次设备号数目,一般默认为1. 相关实现代码如下: int result; d ...