leetcode 231. Power of Two
来源:互联网 发布:淘宝钱夫人衣服好火啊 编辑:程序博客网 时间:2024/06/05 21:07
231. Power of Two
Given an integer, write a function to determine if it is a power of two.
判断是不是2的次方数。2的次方数的二进制有个特点,就是只是1位是1,其他都是0。而这个数-1的二进制那就是 这一位是0,后面的所有位都是1.
所以可以这两个数按为与。
class Solution {public: bool isPowerOfTwo(int n) { return n > 0 && ((n & (n - 1)) == 0); }};
阅读全文
0 0
- [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
- 231. Power of Two LeetCode
- [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
- LeetCode 231. Power of Two
- Leetcode-231. Power of Two
- #leetcode#231. Power of Two
- 231.[Leetcode]Power of Two
- Leetcode 231. Power of Two
- Fortran开发环境在Win7 64位下配置:Compaq Visual Fortran6.5 or 6.6
- 大数据正式11
- 即时通讯网
- 盘点 2017 年度最受欢迎的十大 Linux 服务器发行版
- sitemesh装饰器
- leetcode 231. Power of Two
- request(HttpServletRequest)对象 【get方法】
- 千兆网卡和普通网卡有什么区别?如何判断?
- win7下IIS的安装和配置 图文教程
- zoj2876Phone List题解
- 小玩具——温度采集项目(二)
- 如何扛住1.8亿/秒的双11数据洪峰?阿里流计算技术全揭秘
- JVM——Java虚拟机架构
- STL源码剖析——STL算法之find查找算法