Search topics...

Running Sum of 1d Array

easy
arrayTime: O(n)Space: O(n)Frequency: 3

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

Example 1:

Input: nums = [1, 2, 3, 4]
Output: [1, 3, 6, 10]
Explanation: Running sum: [1, 1+2, 1+2+3, 1+2+3+4]

Example 2:

Input: nums = [3, 1, 2, 10, 1]
Output: [3, 4, 6, 16, 17]
prefix-sum