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. [Contest20180314]数列

    数据范围告诉我们要写两档的分 第一档:$M\leq200,N\leq10^9$,可以枚举$m$计算答案 直接矩阵快速幂:$O\left(M^4\log_2N\right)$,会超时,所以我们需要某些“ ...

  2. python3 开发面试题(装饰器必须考)6.4

    def f(): print("2018-06-04") # 每次调用f的时候 在打印"2018-06-04" 之前打印一句 开始, 之后再打印一句 结束 de ...

  3. 程序调控和监视(Logcat,Debug)

    1.Logcat 2.效果图:实现点击Button,提示Logcat信息 (1)activity_main.xml <?xml version="1.0" encoding= ...

  4. iOS开发——异常:[__NSCFNumber length]: unrecognized selector sent to instance

      *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumbe ...

  5. 解决Ubuntu 14下,PhpStorm 9.x 编辑器界面中文乱码的问题

    在Ubuntu 14中,安装了 PhpStorm 9.02,发现 软件界面中文乱码,但是源码编辑处却显示正常,如下图所示: 很奇怪,猜想,应该是软件界面字体有问题,选了一个没有包含中文字体的字体.先前 ...

  6. Linux之ps查找进程用kill终止命令

    http://www.cnblogs.com/peida/archive/2012/12/20/2825837.html http://blog.csdn.net/andy572633/article ...

  7. 【前后台分离模式下,使用OAuth Token方式认证】

    AngularJS is an awesome javascript framework. With it’s $resource service it is super fast and easy ...

  8. 使用Faric+Git进行分布式代码管理

    Fabric是一个Python库,可以通过SSH在多个host上批量执行任务. 可以通过编写任务脚本,然后通过Fabric在本地就可以使用SSH在大量远程服务器上自动运行. 这些功能非常适合应用的自动 ...

  9. 爬虫扒下 bilibili 视频信息

    B站算是对爬虫非常非常友好的网站啦! 修改转载已取得腾讯云授权 在以上两篇文章中我们已经在腾讯云服务器上搭建好了 Python 爬虫环境了,下一步就是在云服务器上爬上我们的爬虫,抓取我们想要的数据: ...

  10. PostgreSQL数据库的安装与配置

    项目中要用PostgreSQL,所以专门学习了一下如何安装和调试postgresql,此博文用来记录自己的安装和调试过程,安装环境是centos7. 首先尝试了yum安装,因为毕竟yum安装简单粗暴, ...