easyLoops and basicsPrefix sums target 15 min
Running sum
Given a list of numbers nums, return a new list of the same length where the item at position i is the sum of nums[0] through nums[i].
Example 1
Input
nums = [1, 2, 3, 4]Output[1, 3, 6, 10]1, then 1 + 2, then 1 + 2 + 3, then 1 + 2 + 3 + 4.
Example 2
Input
nums = [3, -1, 2]Output[3, 2, 4]Constraints
0 ≤ len(nums) ≤ 105
-106 ≤ nums[i] ≤ 106
Plan it first
Write a line for each before you code, then say them out loud. Compare with the Approach tab afterwards.
Run examples checks the examples. Submit runs every test, including edge cases and, when the problem has one, a speed check on a large input.