Power of Two
来源:互联网 发布:nginx禁止代理ip访问 编辑:程序博客网 时间:2024/06/06 08:41
Given an integer, write a function to determine if it is a power of two.
判断一个数是不是2的指数。
如果是2的指数,那么它的二进制表示就只有一个1.所有n与n-1是否等于0就可以判断。
public class Solution { public boolean isPowerOfTwo(int n) { if(n<=0) return false;return (n&(n-1))==0; }}
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
- wamp安装memcached php方法win32
- jvm基础知识四---垃圾回收面临的问题
- 题目1185:特殊排序
- 机房收费之组合查询
- URLConnection的连接、超时、关闭用法总结
- Power of Two
- Effective Objective-C 2.0 第2条:在类的头文件中尽量少引入其它头文件
- 如何获取Input标签自定义属性的值
- jQuery动画入门--顺序执行
- Objective-C语法之代码块(block)的使用
- 平方根的异常
- poj解题报告——3537
- 如何在android 系统 C/C++ 层中添加 log 信息
- 【图像配准】基于灰度的模板匹配算法(二):局部灰度值编码