【LEETCODE】231-Power of Two
来源:互联网 发布:ubuntu下安装win10 编辑:程序博客网 时间:2024/06/14 06:38
Given an integer, write a function to determine if it is a power of two.
题意:
给一个整数,写一个函数判断它是否是2的幂
参考:
http://bookshadow.com/weblog/2015/07/06/leetcode-power-of-two/
思路:
如果一个整数是2的幂,那么它的二进制形式最高位为1,其余各位为0
等价于:n & (n - 1) = 0,且n > 0
class Solution(object): def isPowerOfTwo(self, n): """ :type n: int :rtype: bool """ return n>0 and n&(n-1)==0
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
- Power of Two(leetcode 231)
- 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】231Power of Two
- 【LeetCode】231Power of Two
- LeetCode 231 Power of Two
- LeetCode 231:Power of Two
- 阿里云linux web服务器 相关配置
- C/C++判断文件是否存在
- Android-Spelling Checker Framework
- osgi加载模式引发的错误
- window10下出现宽带断线解决办法
- 【LEETCODE】231-Power of Two
- Java Unicode 编码互转
- 问题贴,谁告诉我这作业如何完成
- <img>
- STL_算法_最小值和最大值(min_element、max_element)
- 设计模式系列模式总预览
- 摄像头处理yuv转RGB的计算方法:
- 递归地删除目录
- 动态代理总结