leetCode(32):Power of Two
来源:互联网 发布:mysql语句入门 编辑:程序博客网 时间:2024/04/29 05:45
Given an integer, write a function to determine if it is a power of two.
2的幂的二进制表示中,必然只有一个“1”,且不可能为负数。
class Solution {public: bool isPowerOfTwo(int n) { if(n<0) {//若为负数则直接返回 return false; } int num=0; while(n) {//统计1的个数 n=n&(n-1); num++; } if(num==1) return true; return false; }};
0 0
- leetCode(32):Power of Two
- [LeetCode] Power of Two
- 【LeetCode】Power of Two
- [Leetcode]Power of Two
- [leetCode] Power of Two
- leetcode --Power of Two
- leetcode: Power of Two
- LeetCode Power of Two
- [LeetCode] Power of Two
- LeetCode Power of Two
- [leetcode] Power of Two
- [Leetcode]Power of Two
- Leetcode: Power of Two
- [LeetCode]Power of Two
- leetcode | Power of Two
- 【leetcode】Power of Two
- [LeetCode]Power of Two
- [leetcode] Power of two
- Android面试题3之描述下Android的系统架构
- git操作
- 牛顿迭代法
- Linux内核启动常见错误
- 烽火通信实习应聘经验
- leetCode(32):Power of Two
- WIN32 查看进程中已有的程序
- C++ 复制构造函数为啥用引用作为对象
- 自定义android进度条
- Matlab移植到Eigen用到的词条
- linux下怎么杀掉所有子进程
- 设计模式之Flyweight模式(笔记)
- 获取状态栏以及导航栏的高度
- android studio 代码混淆如何忽略第三方jar包