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

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1780

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