zoukankan      html  css  js  c++  java
  • leetcode——231.2的幂

    class Solution(object):
        def isPowerOfTwo(self, n):
            """
            :type n: int
            :rtype: bool
            """
            if n<=0:
                return False
            if n==1:
                return True
            while n>1:
                if n%2!=0:
                    return False
                else:
                    n=n//2
            return True
    执行用时 :16 ms, 在所有 Python 提交中击败了95.32%的用户
    内存消耗 :11.7 MB, 在所有 Python 提交中击败了25.00%的用户
    执行用时为 4 ms 的范例
    import math 
    class Solution(object):
        def isPowerOfTwo(self, n):
            if n == 1:
                return True
            if n<1:
                return False
            while True:
                if n%2 == 0:
                    n /= 2
                    if n == 1:
                        return True
                else:
                    return False

                                                                ——2019.10.10

     
     
     
    我的前方是万里征途,星辰大海!!
  • 相关阅读:
    人月神话2
    cJson 常见用法
    Python C扩展
    动态链接--运行时加载dlopen
    mtrace 简介
    Linux coredump
    动态链接--so的搜索过程
    线程同步--条件变量
    编译过程学习
    Linux 信号
  • 原文地址:https://www.cnblogs.com/taoyuxin/p/11649359.html
Copyright © 2011-2022 走看看