Problem solving/Algorithms

[LeetCode] 1480. Running Sum of 1d Array (Python)

Young_A 2021. 1. 9. 14:16

๋ชฉ์ฐจ

    LeetCode - Problems - Algorithms - 1480. Running Sum of 1d Array

    Problem Description

    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.

     

    Examples:

    Constraints:

    • 1 <= nums.length <= 1000
    • -10^6 <= nums[i] <= 10^6

    My Solution (Python)

    class Solution:
        def runningSum(self, nums):
            answer = []
            current_sum = 0
    
            for x in nums:
                current_sum += x
                answer.append(current_sum)
            
            return answer