Skip to content

Commit 839f6fc

Browse files
authored
Create minimum-value-to-get-positive-step-by-step-sum.py
1 parent 3400c71 commit 839f6fc

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def minStartValue(self, nums):
6+
"""
7+
:type nums: List[int]
8+
:rtype: int
9+
"""
10+
min_prefix, prefix = 0, 0
11+
for num in nums:
12+
prefix += num
13+
min_prefix = min(min_prefix, prefix)
14+
return 1-min_prefix

0 commit comments

Comments
 (0)