Running Sum of 1d Array
Solution ApproachWas this helpful?
Easy•array•Expected: O(n) time, O(n) space
prefix-sum
Problem
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]
Reference solution unlocks after your first submission
Loading...
