thiagowfx's avatar

Β¬ just serendipity πŸ€ (not just serendipity)

LeetCode #1480: Running Sum of 1d Array

β€’ 52 words β€’ 1 min β€’ updated

LeetCode #1480: Running Sum of 1d Array:

python
from itertools import accumulate

class Solution:
    def runningSum(self, nums: List[int]) -> List[int]:
        return list(accumulate(nums))

Primitives:

python
from itertools import accumulate

class Solution:
    def runningSum(self, nums: List[int]) -> List[int]:
        ans = []

        acc = 0
        for num in nums:
            acc += num
            ans.append(acc)

        return ans