惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

雷峰网
雷峰网
B
Blog
博客园_首页
云风的 BLOG
云风的 BLOG
S
SegmentFault 最新的问题
罗磊的独立博客
Jina AI
Jina AI
C
Check Point Blog
Martin Fowler
Martin Fowler
J
Java Code Geeks
博客园 - 司徒正美
美团技术团队
MongoDB | Blog
MongoDB | Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
大猫的无限游戏
大猫的无限游戏
有赞技术团队
有赞技术团队
U
Unit 42
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
小众软件
小众软件

博客园 - db2zos

从假后端到 Cloudflare D1:一次医疗旅游网站的重构实践 没想到老外在中国还可以开车呀 用 API 获取官方统计数据,原来可以这么简单 放弃ipup系列,开始使用更先进的nmcli来管理你的网络 定期启动vpn - db2zos 几段Python小程序 关于职业的一点忧虑和思考 select in 在postgresql的效率问题 Ansible 学习笔记 ldap配置记录 nis,nfs,pam小结 docker命令小记 性能调优利器之strace 如何写出优雅的Python(二) 如何写出优雅的Python 分布式数据库架构一例 如何写出优雅的Python之设置class缺省值 Mac 使用笔记 开启刷题模式 从简单需求到OLAP的RANK系列函数 数据库的Index Scan V.S. Rscan
[LeeCode]Power of Two
db2zos · 2015-07-19 · via 博客园 - db2zos

Given an integer, write a function to determine if it is a power of two.

My initial code:

 1 class Solution:
 2     # @param {integer} n
 3     # @return {boolean}
 4     def isPowerOfTwo(self, n):
 5         if n==0 :
 6             return False
 7         if n==1 or n==2:
 8             return True
 9         if n % 2 != 0:
10             return False
11         if n < 4 and n 
12         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