2025-08-13 14:56:30 +0000 UTC

Power of Three

Code

class Solution:
    def isPowerOfThree(self, n: int) -> bool:
        if n <= 0:
            return False
        while n % 3 == 0:
            n //= 3
        return n == 1