[leetcode][python3] 1480번 - Running Sum of 1d Array

numango·2024년 9월 12일

leetcode

목록 보기
7/12

문제
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.

Example 1:

Input: nums = [1,2,3,4]
Output: [1,3,6,10]
Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].


nums의 i 요소까지의 합으로 이루어진 배열을 반환한다.

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

0개의 댓글