'''
Given an integer, write a function to determine if it is a power of three.
'''
class Solution(object):
#120ms, 11.8MB
def isPowerOfThree(self, n):
"""
:type n: int
:rtype: bool
"""
if n <= 0: return False
if n == 1: return True
else:
while n % 3 == 0:
n = n//3
if n == 1: return True
return False
No comments:
Post a Comment