forked from bregman-arie/python-exercises
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsolution.py
More file actions
24 lines (19 loc) · 659 Bytes
/
Copy pathsolution.py
File metadata and controls
24 lines (19 loc) · 659 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python
from typing import List
def running_sum(nums_li: List[int]) -> List[int]:
"""Returns the running sum of a given list of numbers
Args:
nums_li (list): a list of numbers.
Returns:
list: The running sum list of the given list
[1, 5, 6, 2] would return [1, 6, 12, 14]
Time Complexity: O(n)
Space Complexity: O(n)
"""
for i in range(1, len(nums_li)):
nums_li[i] += nums_li[i - 1]
return nums_li
if __name__ == '__main__':
nums_str = input("Insert numbers (e.g. 1 5 1 6): ")
nums_li = [int(i) for i in nums_str.split()]
print(running_sum(list(nums_li)))