2624. Difference Between Element Sum and Digit Sum of an Array
My accepted Python solution to LeetCode problem 2624, Difference Between Element Sum and Digit Sum of an Array, running in 55ms.
- Difficulty: Easy
- Python
- Runtime 55ms
- Memory 12.8MB
- 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 55ms, memory 12.8MB, accepted 2025-12-24.
class Solution(object):
def differenceOfSum(self, nums):
element_sum = sum(nums)
digit_sum = sum(int(d) for num in nums for d in str(num))
return abs(element_sum - digit_sum)