231. Power of Two
来源:互联网 发布:snapseed是什么软件 编辑:程序博客网 时间:2024/06/10 18:41
/*Given an integer, write a function to determine if it is a power of two.判断一个数是否为2的幂*/class Solution {public: bool isPowerOfTwo(int n) { if(n<=0) return false; int cnt=0; for(int i=0;i<32;i++) { cnt += n&1; n>>=1; } return cnt==1 ? true : false; } bool isPowerOfTwo2(int n) { if(n<=0) return false; return !(n&(n-1)); }};
阅读全文
0 0
- 231. Power of Two
- 231. Power of Two
- 231. Power of Two
- 231. Power of Two
- 231. Power of Two
- 231. Power of Two
- 231. Power of Two
- 231. Power of Two
- 231. Power of Two
- 231. Power of Two
- 231. Power of Two
- 231. Power of Two
- 231. Power of Two
- 231. Power of Two
- 231. Power of Two
- 231. Power of Two
- 231. Power of Two
- 231. Power of Two
- 利用容器快速部署openvas
- Cobbler部署指南之安装虚拟化Xen系统篇
- java中原子变量AtomicInteger等用法
- 第十章——UITableView 和 UITableViewController
- C++虚函数
- 231. Power of Two
- Predict the Winner问题及解法
- Android休眠唤醒2
- Linux JDK升级
- svn的使用
- Cobbler部署指南之电源管理篇
- Connection reset by peer的常见原因
- 抓包工具Fidder详解(主要来抓取Android中app的请求)
- 数据结构-队列 JAVA语言实现