当前位置: 代码迷 >> 综合 >> Leetcode 1413. Minimum Value to Get Positive Step by Step Sum
  详细解决方案

Leetcode 1413. Minimum Value to Get Positive Step by Step Sum

热度:54   发布时间:2023-12-12 21:10:42.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 = 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

  1. https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum/
  相关解决方案