LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 55ms, memory 12.8MB, accepted 2025-12-24.

python
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)

Source