231. Power of Two
2016-03-18 21:01
399 查看
Given an integer, write a function to determine if it is a power of two.
就是看n是不是2的幂,n&(n-1)可以找出n中二进制下有多少1
就是看n是不是2的幂,n&(n-1)可以找出n中二进制下有多少1
public class Solution { public boolean isPowerOfTwo(int n) { if(n<=0)return false; return ((n&(n-1))==0);//n&(n-1)用在判断二进制数中有多少个1存在非常好用 } }
相关文章推荐
- python 分布式进程
- 【五校联考2day2】WYF的盒子
- adb 一次性push多个apk
- 简单理解Android的Fragement组件
- ctf中杂项试题解析
- 面经
- 202. Happy Number
- TextToSpeech的UtteranceProgressListener触发问题
- freemarker获取list<Javabean>的值
- nyoj325 zb的生日
- 简单脱壳教程笔记(3)---手脱UPX壳(2)
- 105. Construct Binary Tree from Preorder and Inorder Traversal | Java最短代码实现
- 初识ASP.NET Core 1.0
- json转bean对象
- 基于分治策略的排序算法:合并排序和快速排序
- 软件开发流程
- 263. Ugly Number
- 有返回结果的页面跳转
- Hush Framework 作为PHP服务端框架
- HDOJ 2014 青年歌手大奖赛_评委会打分