Skip to content

Latest commit

 

History

History
21 lines (18 loc) · 746 Bytes

1480.md

File metadata and controls

21 lines (18 loc) · 746 Bytes

Iterate through the input array, maintaining a cumulative sum of the values observed so far, updating the values stored within the array accordingly.

class Solution:
    def runningSum(self, nums: List[int]) -> List[int]:
        count = 0
        for i, num in enumerate(nums):
            count += num
            nums[i] = count
        return nums

Iterate through the input array, setting the value at each position equal to the sum of the orginal value (at that position) and the value of the element now preceeding it within the array.

class Solution:
    def runningSum(self, nums: List[int]) -> List[int]:
        for i in range(1, len(nums)):
            nums[i] += nums[i-1]
        return nums