326. Power of Three
All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : March 04, 2025
Last updated : March 04, 2025
Related Topics : Math, Recursion
Acceptance Rate : 47.69 %
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)