LeetCode231 Power of Two

LeetCode231 Power of Two
解题思路:用递归的思想解决,先判断是否等于0 或是否是2 的倍数,然后判断是否为1。

class Solution(Object):
    def isPowerOfTwo(self,n):
        if n==0 or n%2>0:
            return False
        if n==1:
        return True
        return self.isPowerOfTwo(n/2)

猜你喜欢

转载自blog.csdn.net/shiyueyue0822/article/details/78083884
今日推荐