给定一个纯数字列表,请编写一个函数,从索引0的位置开始,每个元素向后汇总计算和值,以此类推,直至汇总结果为0。返回所有汇总值组成的列表。
示例:
输入:[0, 1, 3, 6, 10]
过程:[0, 1, 3, 6, 10]
,和值:20
过程:[1, 3, 6, 10]
,和值:20
过程:[3, 6, 10]
,和值:19
过程:[6, 10]
,和值:16
过程:[10]
,和值:10
过程:[]
,和值:0
题目难度:简单
题目来源:CodeWars:Sums of Parts
def solution(nums: list) -> list:
# your code here
assert solution([1, 2, 3, 4, 5, 6]) == [21, 20, 18, 15, 11, 6, 0]
assert solution([0, 1, 3, 6, 10]) == [20, 20, 19, 16, 10, 0]
assert solution([744125, 935, 407, 454, 430, 90, 144, 6710213, 889, 810, 2579358]) == [10037855, 9293730, 9292795, 9292388, 9291934, 9291504, 9291414, 9291270, 2581057, 2580168, 2579358, 0]