< Back




1480. Running Sum of 1d Array

Using the original array, we just traverse the array from array[1] to array[n], adding to array[i]
the value of the previous element in the array, array[i-1].

The solution is as follows:


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

          return nums


_ Time Complexity:

  O(n) - We traverse the array once.

_ Space Complexity:

  O(1) - We modify the array in-place.