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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 0ms, memory 17.6MB, accepted 2026-01-01.
class Solution:
def checkPowersOfThree(self, n: int) -> bool:
while n > 0:
if n % 3 == 2:
return False
n //= 3
return True