Solution 1
class Solution:
def isPowerOfThree(self, n: int) -> bool:
maxint = 2 ** 31 - 1
return n > 0 and 3 ** int(math.log(maxint,3)) % n == 0
Time complexity is O(1). Space complexity is O(1).
Solution 1
class Solution:
def isPowerOfThree(self, n: int) -> bool:
maxint = 2 ** 31 - 1
return n > 0 and 3 ** int(math.log(maxint,3)) % n == 0
Time complexity is O(1). Space complexity is O(1).