231、326、342 Power of Two

题目

在这里插入图片描述
判断一个数是不是2的n次方。几道题目是同理的。

我的代码

class Solution(object):
    def isPowerOfTwo(self, n):
        """
        :type n: int
        :rtype: bool
        """
        if n==1:
            return True
        i=2
        while i<n:
            i*=2
        return i==n

猜你喜欢

转载自blog.csdn.net/xiabenshu/article/details/88995800
今日推荐