Neighbor Sums

Sometimes nearby values matter more as pairs than as separate elements, like sales totals for two neighboring days. The function pairwise_sums receives a list of numbers nums and returns a list of sums of adjacent elements. If the list has fewer than two numbers, there is nothing to add, so return an empty list.

Примеры

Ввод
[1, 2, 3]
Вывод
[3, 5]
Ввод
[5]
Вывод
[]
Ввод
[]
Вывод
[]

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

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

Теги

lists
PostgreSQLv16

Тук ще се появи резултатът от изпълнението на кода

Visible tests
1
Input
[1,2,3]
Expected[3,5]
2
Input
[5]
Expected[]
3
Input
[]
Expected[]
4
Input
[1,2,3,4]
Expected[3,5,7]
5
Input
[-1,1,-1]
Expected[0,0]
6
Input
[2,3,4]
Expected[5,7]
Focus radio
Paused · SomaFM · Fluid