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
- 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.4MB, accepted 2025-12-31.
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