文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
1. Description
2. Solution
- Version 1
class Solution:def minStartValue(self, nums):min_value = nums[0]total = 0for num in nums:total += numif total < min_value:min_value = totalif min_value >= 1:return 1else:return 1 - min_value
- Version 2
class Solution:def minStartValue(self, nums):min_value = 0total = 0for num in nums:total += numif total < min_value:min_value = totalreturn 1 - min_value
Reference
- https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum/