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)
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)