Power of Two
来源:互联网 发布:跟兄弟连学php.pdf下载 编辑:程序博客网 时间:2024/06/10 19:49
https://leetcode.com/problems/power-of-two/
Given an integer, write a function to determine if it is a power of two.
数字 2^n 是大于0的,而且等于1左移n位得到的数字,所以2^n与2^n-1 相与运算得到0.
bool isPowerOfTwo(int n) { if(n <= 0) return false; if((n & (n-1)) == 0) return true; return false;}
bool isPowerOfTwo(int n) { return n > 0 && !(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
- 【9701】求余运算
- 按照圆周顺时针布局多个view
- GIT使用
- opencv之边缘检测
- CI框架中浏览量(点击次数)
- Power of Two
- HDU Problem - 5363 Key Set 【快速幂】
- POJ1325
- 关于Cache-Control: no-cache和no-store
- linux中设置环境变量和gcc/g++的include路径
- 利用docker-compose和docker-swarm搭建ELK环境
- android学习笔记之运动事件MotionEvent
- WWW-万维网详解
- MyEclipse——快捷键的使用