Skip to content

Latest commit

 

History

History
55 lines (42 loc) · 1.26 KB

_326. Power of Three.md

File metadata and controls

55 lines (42 loc) · 1.26 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : March 04, 2025

Last updated : March 04, 2025


Related Topics : Math, Recursion

Acceptance Rate : 47.69 %


Solutions

Python

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

        return True
class Solution:
    def isPowerOfThree(self, n: int) -> bool:
        return n >= 1 and (n == 1 or n // 3 * 3 == n and self.isPowerOfThree(n // 3))
class Solution:
    def isPowerOfThree(self, n: int) -> bool:
        return n > 0 and n == 3 ** int(log(n, 3) + 0.0001)