美文网首页Leetcode
Leetcode 1413. Minimum Value to

Leetcode 1413. Minimum Value to

作者: SnailTyan | 来源:发表于2021-02-20 13:04 被阅读0次

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

Minimum Value to Get Positive Step by Step Sum

2. Solution

  • Version 1
class Solution:
    def minStartValue(self, nums):
        min_value = nums[0]
        total = 0
        for num in nums:
            total += num
            if total < min_value:
                min_value = total
        if min_value >= 1:
            return 1
        else:
            return 1 - min_value
  • Version 2
class Solution:
    def minStartValue(self, nums):
        min_value = 0
        total = 0
        for num in nums:
            total += num
            if total < min_value:
                min_value = total
        return 1 - min_value

Reference

  1. https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum/

相关文章

网友评论

    本文标题:Leetcode 1413. Minimum Value to

    本文链接:https://www.haomeiwen.com/subject/chlnxltx.html