Running Sum of 1d Array - LeetCode

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.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/e2ef56f2-7b21-4234-b248-e9d02f978187/Screen_Shot_2021-03-29_at_3.29.12_PM.png

write

write

"""
1480. Running Sum of 1d Array

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.

Input: nums = [1,2,3,4]
Output: [1,3,6,10]
Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4]
"""

List = [1,2,3,4]
new_List = []
total = 0
i = 0

new_List.append(List[0])

while i < len(List) - 1:
    new_List.append(new_List[i] + List[i + 1])

    i += 1

print(new_List)

in leetcode

in leetcode