Numbers Versus Digits

Sometimes it is useful to look at numbers in two ways: as whole values and as separate digits. Write a function difference_of_sum that first finds the sum of all numbers in nums, then finds the sum of all digits inside those numbers. Return the absolute difference between these two sums.

Примеры

Ввод
[1, 15, 6, 3]
Вывод
9
Ввод
[1, 2, 3, 4]
Вывод
0
Ввод
[10]
Вывод
9

Нужно реализовать

def difference_of_sum(nums: list[int]) -> int:

Теги

arraymath
PostgreSQLv16

Siia ilmub koodi käivituse tulemus

Visible tests
1
Input
[1,15,6,3]
Expected9
2
Input
[1,2,3,4]
Expected0
3
Input
[10]
Expected9
4
Input
[100]
Expected99
5
Input
[5]
Expected0
6
Input
[99,99]
Expected162
Focus radio
Paused · SomaFM · Fluid