[LeeCode]Power of Two
2015-07-19 15:28
176 查看
Given an integer, write a function to determine if it is a power of two.
My initial code:
After google the internet, the best solution is:
My initial code:
class Solution: # @param {integer} n # @return {boolean} def isPowerOfTwo(self, n): if n==0 : return False if n==1 or n==2: return True if n % 2 != 0: return False if n < 4 and n return self.isPowerOfTwo(n/2)
After google the internet, the best solution is:
class Solution: # @param {integer} n # @return {boolean} def isPowerOfTwo(self, n): if n<= 0 or n&(n-1) != 0: return False return True
相关文章推荐
- Centos 6.5 配置hadoop2.7.1
- 极客学院 java 集合使用 简单代码
- 点是否在 三角形,凸多边形, 凹多边形,四面体内 的判断
- 【LeetCode 34】Search for a Range
- COM线程模型调试
- [LeetCode]Permutations II(!!!!!DFS递归&&回溯)
- Apache的prefork模式和worker模式
- html5实现带提示文字的输入框(摆脱js)
- 数据表
- Hadoop Counter
- 2015/7/19 Django学习之入门
- Git基础---Git常用命令
- [Android]The connection to adb is down, and a severe error has occured.
- java创建二叉树并实现非递归中序遍历二叉树
- VS2012如何创建模板
- 学习MongoDB 七: MongoDB索引(索引基本操作)(一)
- dos格式转变为unix格式 总结
- C++中的unique(),unique_copy()的用法
- Zend Studio实用快捷键一览表
- cookies的存值问题