Power of Two
来源:互联网 发布:网络综合布线工程实施 编辑:程序博客网 时间:2024/04/30 06:19
题目:Given an integer, write a function to determine if it is a power of two.
判断一个数是否是2的幂,如果是2的幂的话,这个数最高位是1,这个数减1,除最高位,其余都为零,利用这个特点,可以判断出是否是2的幂。
class Solution {public: bool isPowerOfTwo(int n) { if(n<=0) { return false; } return !(n&(n-1)); }};
0 0
- Power of Two
- [LeetCode] Power of Two
- 【LeetCode】Power of Two
- Power of Two
- power of two
- [Leetcode]Power of Two
- Power of Two
- [leetCode] Power of Two
- Power of Two
- 231Power of Two
- leetcode --Power of Two
- Power of Two
- leetcode: Power of Two
- Power of Two
- Power of Two
- Power of Two
- Leetcode46: Power of Two
- LeetCode Power of Two
- 十三章QQ项目查询 删除插入
- JAVA入门笔记4:方法
- LCA 问题 Tarjan算法
- Android数据存储和访问—书籍的增删检查
- Roadblocks
- Power of Two
- Auth2.0开发
- Android - Log的等级: Verbose,Debug,Info,Warn,Error - ALOGV,ALOGD,ALOGI,ALOGW,ALOGE
- 通向架构师的道路(第一天)之Apache整合Tomcat
- Git基础篇
- CCF交通规划
- Markdown 使用方法摘要
- 设备地址与IO内存映射
- java遍历无极树的源码