LeetCode solutions

4135. Concatenate Non-Zero Digits and Multiply by Sum I

My accepted Python solution to LeetCode problem 4135, Concatenate Non-Zero Digits and Multiply by Sum I, running in 0ms.

  • Difficulty: Easy
  • Python
  • Runtime 0ms
  • Memory 17.4MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.4MB, accepted 2025-12-31.

python
class Solution:
    def sumAndMultiply(self, n: int) -> int:
        # Get non-zero digits as a string
        non_zero = ''.join(c for c in str(n) if c != '0')
        
        if not non_zero:
            return 0
        
        x = int(non_zero)
        digit_sum = sum(int(c) for c in non_zero)
        
        return x * digit_sum

Source