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
Melde dich an, um den Einreichungsverlauf zu sehen
AnmeldenMelde dich an, um den KI-Mentor zu nutzen
AnmeldenVisible tests
1
Input
[1,15,6,3]Expected
92
Input
[1,2,3,4]Expected
03
Input
[10]Expected
94
Input
[100]Expected
995
Input
[5]Expected
06
Input
[99,99]Expected
162Focus radio
Paused · SomaFM · Fluid