位操作-leetcode 231 Power of Two
来源:互联网 发布:淘宝二级词是什么 编辑:程序博客网 时间:2024/05/22 15:39
原题链接:Power of Two
分析:判断一个数是不是2的次方,显然,n<=0不是,那么对于正整数,如果是2的次方,必然只有二进制位只有一个1.所以,代码就很容易了。
题解:
class Solution {public: bool isPowerOfTwo(int n) { /* Time Complexity:O(1) */ if(n<=0)return false; return n&(n-1)?false:true; }};
阅读全文
0 0
- 位操作-leetcode 231 Power of Two
- LeetCode 231 Power of Two (位运算)
- leetcode 231. Power of Two 神奇的位操作
- leetcode Power of Two位运算
- LeetCode Power of Two 位运算
- leetcode-231 Power of Two
- leetcode 231:Power of Two
- LeetCode 231: Power of Two
- leetcode 231: Power of Two
- leetcode[231]:Power of Two
- Power of Two(leetcode 231)
- leetcode-231-Power of Two
- LeetCode 231 Power of Two
- leetCode #231 Power of Two
- leetcode 231: Power of Two
- [Leetcode]#231 Power of Two
- Leetcode #231 Power of Two
- [LeetCode 231] Power of Two
- CALayer与iOS动画 讲解及使用
- 7.3
- [杜教筛] 51Nod 1244: 莫比乌斯函数之和
- 学院网站的建设
- boost log库学习使用四(关于logger)
- 位操作-leetcode 231 Power of Two
- caffe框架特征提取的dll封装
- href="javascript:xxx(this);"和onclick="javascript:xxx(this);"的区别
- (10)break,continue用法
- 第三章 Redis/SSDB+Twemproxy安装与使用
- Intellij中出现Connot resolve Struts Package 'struts-default'错误的原因
- 【Linux 虚拟机】Windows 7下用VMware Workstation 10虚拟机安装 Ubuntu 14.04
- markdown在Windows10下安装后启动出现的错误以及一些解决方案
- matlab 数据拟合