Running Sum of an Array (Set 10)

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 10) — the data. This set runs 4 cases: nums holds arrays of 41–47 items, with values from -39 to 79. The hidden cases are the largest of the set.

Example 1

runningSum()
Input
nums = [25, -20, 62, 69, 24, 0, 21, 69, 52, -32, -37, 53, -12, -36, 22, 34, 46, 7, 67, -14, -36, 7, 30, 35, -38, 63, -2, 51, 69, 8, 25, 38, 79, -24, -16, 28, 39, 15, 29, 7, 55]
Output
[25, 5, 67, 136, 160, 160, 181, 250, 302, 270, 233, 286, 274, 238, 260, 294, 340, 347, 414, 400, 364, 371, 401, 436, 398, 461, 459, 510, 579, 587, 612, 650, 729, 705, 689, 717, 756, 771, 800, 807, 862]

Why

`runningSum` returns `[25, 5, 67, 136, 160, 160, 181, 250, 302, 270, 233, 286, 274, 238, 260, 294, 340, 347, 414, 400, 364, 371, 401, 436, 398, 461, 459, 510, 579, 587, 612, 650, 729, 705, 689, 717, 756, 771, 800, 807, 862]` for this input.

Example 2

runningSum()
Input
nums = [-16, 33, -13, 10, 62, 48, 23, -14, 57, 19, 37, 77, -22, -31, -21, -19, -10, -7, -5, -14, 19, 16, 62, 31, 43, 51, 67, 30, 17, 45, -24, -34, 62, 22, 0, 10, 44, 22, 46, 47, -38, 32, 69, 56, -2, 23, -15]
Output
[-16, 17, 4, 14, 76, 124, 147, 133, 190, 209, 246, 323, 301, 270, 249, 230, 220, 213, 208, 194, 213, 229, 291, 322, 365, 416, 483, 513, 530, 575, 551, 517, 579, 601, 601, 611, 655, 677, 723, 770, 732, 764, 833, 889, 887, 910, 895]

Why

`runningSum` returns `[-16, 17, 4, 14, 76, 124, 147, 133, 190, 209, 246, 323, 301, 270, 249, 230, 220, 213, 208, 194, 213, 229, 291, 322, 365, 416, 483, 513, 530, 575, 551, 517, 579, 601, 601, 611, 655, 677, 723, 770, 732, 764, 833, 889, 887, 910, 895]` 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.