Given an integer, write a function to determine whether it is a power of 3.

Example 1:

Input: 27 Output: true Example 2:

Input: 0 Output: false Example 3:

Input: 9 Output: true Example 4:

Input: 45 Output: false Advanced: Can you complete this problem without using loops or recursion?

class Solution:
    def isPowerOfThree(self, n: int) -> bool:
        
        import math
        if n < 1:
            return False
        if n == 1:
            return True
        
        s = math.log(n,3)
        s = round(s,10)
        if s%1 == 0:
            return True
        else:
            return False
Copy the code