본문 바로가기

Algorithm/Implementation

(Python) - LeetCode (easy) 1480. Running Sum of 1d Array

반응형

https://leetcode.com/problems/running-sum-of-1d-array/description/

간단 구현 문제였습니다.

📕 풀이방법

📔 입력 및 초기화

list ans를 선언합니다.

📔 풀이과정

누적해 더한 값을 ans에 append합니다.

📔 정답 출력 | 반환

ans를 반환합니다.


📕 Code

📔 Python

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

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.