LeetCode solutions

1889. Check if Number is a Sum of Powers of Three

My accepted Python solution to LeetCode problem 1889, Check if Number is a Sum of Powers of Three, running in 0ms.

  • Difficulty: Medium
  • Python
  • Runtime 0ms
  • Memory 17.6MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.6MB, accepted 2026-01-01.

python
class Solution:
    def checkPowersOfThree(self, n: int) -> bool:
        while n > 0:
            if n % 3 == 2:
                return False
            n //= 3
        return True

Source