class Solution:
def isPowerOfThree(self, n: int) -> bool:
result = False
x =1
if n ==1:
return True
for i in range(n):
x =x*3
if x ==n:
result =True
break
if x>n:
break
return result