LeetCode solutions

4039. Compute Decimal Representation

My accepted Python solution to LeetCode problem 4039, Compute Decimal Representation, running in 3ms.

  • Difficulty: Easy
  • Python
  • Runtime 3ms
  • Memory 17.3MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 3ms, memory 17.3MB, accepted 2025-12-30.

python
class Solution:
    def decimalRepresentation(self, n: int) -> List[int]:
        result = []
        multiplier = 1
        while n > 0:
            digit = n % 10
            if digit != 0:
                result.append(digit * multiplier)
            n //= 10
            multiplier *= 10
        return result[::-1]  # Descending order

Source