Running Sum

Easy~10 min

Given an array of numbers nums, return an array where each element at index i is the sum of all elements from index 0 to i (inclusive).

In other words, result[i] = nums[0] + nums[1] + ... + nums[i].

Examples

Example 1
Input: nums = [1, 2, 3, 4]
Output: [1, 3, 6, 10]
Explanation: Running sums: [1, 1+2, 1+2+3, 1+2+3+4] = [1, 3, 6, 10].
Example 2
Input: nums = [3, 1, 4, 1, 5]
Output: [3, 4, 8, 9, 14]
Explanation: Running sums: [3, 3+1, 3+1+4, 3+1+4+1, 3+1+4+1+5].
Example 3
Input: nums = [5]
Output: [5]
Explanation: A single element is its own running sum.

Constraints

  • 1 <= nums.length <= 10^4
  • -10^6 <= nums[i] <= 10^6
Code
Ctrl+EnterRun|Ctrl+⇧+EnterSubmit
Output

Run your code to see results

Use Cmd+Enter to run