Running Total

EasyRunning Totals≈ 10 min

You are given a list of integers nums. Return a list of the same length in which the value at index i is the total of all numbers up to and including nums[i].

Examples

text
nums = [1, 2, 3, 4]       →  [1, 3, 6, 10]
nums = [5, -2, 0, 7]      →  [5, 3, 3, 10]
nums = [1, 1, 1, 1, 1]    →  [1, 2, 3, 4, 5]

In the first example the totals are 1, 1 + 2, 1 + 2 + 3 and 1 + 2 + 3 + 4.

Constraints

  • Between 0 and 10,000 numbers, each between -100,000 and 100,000.
  • Aim for O(n): one addition per number.
Sound off. Turn on for key clicks and a chime when the tests pass.Inline suggestions off. Recommended while you are learning. Turn on to complete words as you type.
Console
›Run to see what your code prints

Run checks the 3 visible cases here, in your browser. Submit runs all 7 on the judge, 4 of them hidden, and measures how your solution scales.