Running Sum of an Array (Set 12)

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 12) — the data. This set runs 4 cases: nums holds arrays of 46–48 items, with values from -40 to 80. The hidden cases are the largest of the set.

Example 1

runningSum()
Input
nums = [-30, 20, 41, 21, 79, -34, -23, 45, 53, 20, 75, -32, 41, -38, 46, -9, 57, 32, 9, 26, -19, 70, 79, 7, -35, -12, -26, -19, 30, 47, -28, -8, 65, -1, 70, 3, -23, 48, 32, 15, 57, -40, -26, 14, 26, -8]
Output
[-30, -10, 31, 52, 131, 97, 74, 119, 172, 192, 267, 235, 276, 238, 284, 275, 332, 364, 373, 399, 380, 450, 529, 536, 501, 489, 463, 444, 474, 521, 493, 485, 550, 549, 619, 622, 599, 647, 679, 694, 751, 711, 685, 699, 725, 717]

Why

`runningSum` returns `[-30, -10, 31, 52, 131, 97, 74, 119, 172, 192, 267, 235, 276, 238, 284, 275, 332, 364, 373, 399, 380, 450, 529, 536, 501, 489, 463, 444, 474, 521, 493, 485, 550, 549, 619, 622, 599, 647, 679, 694, 751, 711, 685, 699, 725, 717]` for this input.

Example 2

runningSum()
Input
nums = [57, 24, 62, -23, 29, -34, -11, -5, 29, -15, 33, -22, 60, 54, 52, -32, 11, 15, -25, 74, 25, 45, 17, -19, -30, -16, -7, 34, -22, 2, 6, 12, 57, 23, -20, 47, 72, -30, 59, -31, -19, 14, 27, 13, 18, -15, 11, 13]
Output
[57, 81, 143, 120, 149, 115, 104, 99, 128, 113, 146, 124, 184, 238, 290, 258, 269, 284, 259, 333, 358, 403, 420, 401, 371, 355, 348, 382, 360, 362, 368, 380, 437, 460, 440, 487, 559, 529, 588, 557, 538, 552, 579, 592, 610, 595, 606, 619]

Why

`runningSum` returns `[57, 81, 143, 120, 149, 115, 104, 99, 128, 113, 146, 124, 184, 238, 290, 258, 269, 284, 259, 333, 358, 403, 420, 401, 371, 355, 348, 382, 360, 362, 368, 380, 437, 460, 440, 487, 559, 529, 588, 557, 538, 552, 579, 592, 610, 595, 606, 619]` 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.