Description

Given an array nums, return the running sum of nums where runningSum[i] = sum(nums[0]...nums[i]). This is also known as the prefix sum or cumulative sum of the array.

Examples

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

Running sums.

Input:nums = [5]
Output:[5]
Explanation:

For a single element array, the running sum is just the element itself since there's only one position to sum up to.

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

When the array contains zeros, they don't change the running sum. Position 0: sum=0, Position 1: sum=0+2=2, Position 2: sum=0+2+0=2, Position 3: sum=0+2+0+4=6, Position 4: sum=0+2+0+4+0=6.

Constraints

  • 1 ≤ nums.length ≤ 1000

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!