See Code
class Solution:
def isPowerOfThree(self, n: 'int') -> 'bool':
if not n:
return False
if n == 1:
return True
if n % 3 == 0:
return self.isPowerOfThree(n//3)
else:
return False
# Follow up:
# Could you do it without using any loop / recursion?
class Solution:
def isPowerOfThree(self, n: 'int') -> 'bool':
# 1162261467 is 3^19, 3^20 is bigger than int
return n > 0 and 1162261467 % n == 0