running sum of 1d array code example
Example 1: Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]). Return the running sum of nums.
def running_sum(nums):
sum = 0
result = []
for num in nums:
sum += num
result.append(sum)
return result
Example 2: running sum of array
Input: nums = [1,1,1,1,1]
Output: [1,2,3,4,5]
Explanation: Running sum is obtained as follows: [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1].