LeetCode 231. Power of Two
来源:互联网 发布:知乎南北战争 编辑:程序博客网 时间:2024/06/06 05:45
问题描述:
Given an integer, write a function to determine if it is a power of two.
判断一个数是否为2的次方
举例看2的次方数及其二进制表示如下,
1(0)、2(10)、4(100)、8(1000)、16(10000)······
满足2的次幂的数的二进制表示只有一个1,且一定是最高位为1.
到这里思路就清晰了。
AC代码如下:
bool isPowerOfTwo(int n) { if(n <= 0) return false; return (!(n&n-1)); }
0 0
- [leetcode] 231.Power of Two
- LeetCode ||231. Power of Two
- [LeetCode]231.Power of Two
- Leetcode 231. Power of Two
- leetcode 231. Power of Two
- 231. Power of Two LeetCode
- [LeetCode]231. Power of Two
- [LeetCode]231. Power of Two
- LeetCode 231. Power of Two
- [leetcode] 231. Power of Two
- leetcode 231. Power of Two
- LeetCode *** 231. Power of Two
- leetcode 231. Power of Two
- LeetCode 231. Power of Two
- Leetcode-231. Power of Two
- #leetcode#231. Power of Two
- 231.[Leetcode]Power of Two
- Leetcode 231. Power of Two
- Android:设计之屏幕适配
- Hibernate 左外连接查询
- Activiti - 新一代的开源 BPM 引擎
- C++ explicit的作用
- 3-34 内存输出(打印数据)
- LeetCode 231. Power of Two
- 用最简单的方式实现基于libevent框架的http client客户端
- 教你成为全栈工程师
- 微信URL Scheme
- scala 查看对象类型 check type
- java基础-类型转换
- html文件的中文乱码问题与在浏览器中的显示
- iOS 主线程更新UI
- 基于netty的异步非阻塞实时聊天(IM)服务器