Skip to content

Commit c25ba0d

Browse files
authored
Create 1480_Running_Sum_of_1d_Array.md
1 parent 23d3b01 commit c25ba0d

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

1480_Running_Sum_of_1d_Array.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## 1480. Running Sum of 1d Array
2+
3+
Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]).
4+
5+
Return the running sum of nums.
6+
7+
8+
9+
Example 1:
10+
11+
Input: nums = [1,2,3,4]
12+
Output: [1,3,6,10]
13+
Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].
14+
Example 2:
15+
16+
Input: nums = [1,1,1,1,1]
17+
Output: [1,2,3,4,5]
18+
Explanation: Running sum is obtained as follows: [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1].
19+
Example 3:
20+
21+
Input: nums = [3,1,2,10,1]
22+
Output: [3,4,6,16,17]
23+
24+
25+
Constraints:
26+
27+
1 <= nums.length <= 1000
28+
-10^6 <= nums[i] <= 10^6
29+
30+
```python
31+
def runningSum(self, nums: List[int]) -> List[int]:
32+
result = []
33+
rs = 0
34+
for i in nums:
35+
rs += i
36+
result.append(rs)
37+
return result
38+
```
39+
40+
41+
```
42+
Runtime: 36 ms, faster than 84.68% of Python3 online submissions for Running Sum of 1d Array.
43+
Memory Usage: 14.2 MB, less than 99.99% of Python3 online submissions for Running Sum of 1d Array.
44+
```

0 commit comments

Comments
 (0)