[
array
accumulate
]
Leetcode 1480. Running Sum of 1d Array
Problem statement
https://leetcode.com/problems/running-sum-of-1d-array/
Solution
In python we can use functionality of language and directly use accumulate
function, which will give you iterator, which we need to transform to list. And this is all we need to do here.
Complexity
Time and space complexity is O(n)
, where n
is the length of nums
.
Code
class Solution:
def runningSum(self, nums):
return list(accumulate(nums))