Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- Kaggle
- 금융문자분석경진대회
- 더현대서울 맛집
- ChatGPT
- 프로그래머스
- Baekjoon
- 데이콘
- 코로나19
- Docker
- Git
- 백준
- 파이썬
- 자연어처리
- hackerrank
- 맥북
- AI 경진대회
- ubuntu
- PYTHON
- 우분투
- 프로그래머스 파이썬
- Real or Not? NLP with Disaster Tweets
- programmers
- 편스토랑
- 편스토랑 우승상품
- dacon
- gs25
- leetcode
- 캐치카페
- SW Expert Academy
- github
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 1480. Running Sum of 1d Array (Python) 본문
728x90
반응형
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].
Example 2:
Input: nums = [1,1,1,1,1]
Output: [1,2,3,4,5]
Explanation: Running sum is obtained as follows: [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1].
Example 3:
Input: nums = [3,1,2,10,1]
Output: [3,4,6,16,17]
Constraints:
- 1 <= nums.length <= 1000
- -10^6 <= nums[i] <= 10^6
Solution
class Solution:
def runningSum(self, nums: List[int]) -> List[int]:
answer = []
for i in range(len(nums)):
answer.append(sum(nums[0:i+1]))
return answer
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 917. Reverse Only Letters (Python) (0) | 2020.09.04 |
---|---|
[leetCode] 443. String Compression (Python) (0) | 2020.09.03 |
[leetCode] 728. Self Dividing Numbers (Python) (0) | 2020.09.01 |
[leetCode] 977. Squares of a Sorted Array (Python) (0) | 2020.09.01 |
[leetCode] 1281. Subtract the Product and Sum of Digits of an Integer (Python) (0) | 2020.08.30 |
Comments