给出一个整数,写一个函数来确定这个数是不是3的一个幂。
后续挑战:
你能不使用循环或者递归完成本题吗?
class Solution(object):
def isPowerOfThree(self, n):
"""
:type n: int
:rtype: bool
"""
while n>0:
if n%3==0:
n/=3
else:
break
return True if n==1 else False
后续挑战
class Solution(object):
def isPowerOfThree(self, n):
"""
:type n: int
: