Running Sum

Big-O & the Python Toolkit, problem 1 of 7

Running Sum

Easy

LC #1480

arrayprefix sum

Not attempted yet

Given a list of integers nums, return a new list where position i holds nums[0] + nums[1] + … + nums[i].

Example 1

Input: nums = [1, 2, 3, 4]
Output: [1, 3, 6, 10]

Example 2

Input: nums = [2, 2, 2]
Output: [2, 4, 6]

Example 3

Input: nums = [5, -1, 0, 3]
Output: [5, 4, 4, 7]

Constraints

  • 0 ≤ nums.length ≤ 10⁵
  • -10⁴ ≤ nums[i] ≤ 10⁴

Python

Loading draft…

Test results

8 tests available

No results yet

Run tests your code against the examples; Submit runs the hidden tests too.

3 examples, 5 hidden

Run examples, then submit all tests.