https://leetcode.com/problems/running-sum-of-1d-array/?envType=study-plan&id=level-1
Running Sum of 1d Array - LeetCode
Can you solve this real interview question? Running Sum of 1d Array - 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,
leetcode.com
내 풀이
class Solution:
def runningSum(self, nums: List[int]) -> List[int]:
result = []
result.append(nums[0])
for i in range(1,len(nums)):
result.append(nums[i]+result[i-1])
return result
결과
'알고리즘 > Problem Solving' 카테고리의 다른 글
LeetCode - 205. Isomorphic Strings (0) | 2023.03.20 |
---|---|
파이썬 Problem Solving 시간복잡도 개선 방법 (0) | 2023.03.12 |
LeetCode - 724. Find Pivot Index (0) | 2023.03.12 |
백준 - 가장 긴 증가하는 부분 수열 (11053) (0) | 2021.10.26 |
백준 - 평범한 배낭 (12865) (0) | 2021.10.26 |
댓글