Running Sum of an Array (Set 9)

Easy

Given an array of integers nums, return the running sum: index i of the result holds the sum of nums[0] through nums[i].

Running Sum of an Array (Set 9) — the data. This set runs 4 cases: nums holds arrays of 40–46 items, with values from -40 to 80. The hidden cases are the largest of the set.

Example 1

runningSum()
Input
nums = [46, -15, -29, 46, -17, -40, -30, 17, -2, 33, -25, 43, 24, 48, 31, 52, 79, 14, -31, 80, -10, 63, 63, 31, 5, 50, 49, 36, 61, -25, 33, 63, 80, -17, 34, 29, -10, -9, -15, 23, 23, 72, 46, 57, 11, 41]
Output
[46, 31, 2, 48, 31, -9, -39, -22, -24, 9, -16, 27, 51, 99, 130, 182, 261, 275, 244, 324, 314, 377, 440, 471, 476, 526, 575, 611, 672, 647, 680, 743, 823, 806, 840, 869, 859, 850, 835, 858, 881, 953, 999, 1056, 1067, 1108]

Why

`runningSum` returns `[46, 31, 2, 48, 31, -9, -39, -22, -24, 9, -16, 27, 51, 99, 130, 182, 261, 275, 244, 324, 314, 377, 440, 471, 476, 526, 575, 611, 672, 647, 680, 743, 823, 806, 840, 869, 859, 850, 835, 858, 881, 953, 999, 1056, 1067, 1108]` for this input.

Example 2

runningSum()
Input
nums = [-31, 28, 48, -3, 37, 30, 8, -11, -27, -31, 74, -39, -30, -13, -8, 28, 11, 0, 59, 17, 42, 43, 4, 55, 80, 0, 25, 29, -21, 1, 13, 35, 45, 29, -35, -7, 31, 12, 61, 39, -13]
Output
[-31, -3, 45, 42, 79, 109, 117, 106, 79, 48, 122, 83, 53, 40, 32, 60, 71, 71, 130, 147, 189, 232, 236, 291, 371, 371, 396, 425, 404, 405, 418, 453, 498, 527, 492, 485, 516, 528, 589, 628, 615]

Why

`runningSum` returns `[-31, -3, 45, 42, 79, 109, 117, 106, 79, 48, 122, 83, 53, 40, 32, 60, 71, 71, 130, 147, 189, 232, 236, 291, 371, 371, 396, 425, 404, 405, 418, 453, 498, 527, 492, 485, 516, 528, 589, 628, 615]` for this input.
Constraints
1 <= nums.length <= 10^4
-10^3 <= nums[i] <= 10^3
Every case in this set must pass: the first two are visible on Run, the last two unlock on Submit.

Topics

ArraysPrefix Sum

Implement runningSum in the editor and return the answer — printing it is never graded.