Return the running sum of a one-dimensional array, where each position contains the sum of all elements up to that index.
Given an integer array nums, build a new array runningSum such that runningSum[i] is the sum of the elements from index 0 through index i in nums.
In other words, each entry in the result should represent the cumulative total seen so far as you scan the array from left to right.
nums of length n.runningSum of the same length, where runningSum[i] = nums[0] + nums[1] + ... + nums[i].Example 1
Input
nums = [1,2,3,4]
Output
[1,3,6,10]
Explanation
The cumulative sums are 1, 1+2=3, 1+2+3=6, and 1+2+3+4=10.
Example 2
Input
nums = [1,1,1,1,1]
Output
[1,2,3,4,5]
Explanation
Each position adds one more element to the running total.
Example 3
Input
nums = [3,1,2,10,1]
Output
[3,4,6,16,17]
Explanation
Keep adding the current value to the total seen so far.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.