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

 
 
 
我的前方是万里征途,星辰大海!!
原文地址:https://www.cnblogs.com/taoyuxin/p/11649359.html