thiagowfx's avatar

Β¬ just serendipity πŸ€ (not just serendipity)

LeetCode #326: Power of Three

β€’ 37 words β€’ 1 min β€’ updated

LeetCode #326: Power of Three:

python
class Solution:
    def isPowerOfThree(self, n: int) -> bool:
        if n <= 0:
            return False

        while n != 1:
            if n % 3 != 0:
                return False

            n //= 3

        return True