mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-04 15:01:40 +08:00
国外版
This commit is contained in:
44
算法题(国外版)/minimum-value-to-get-positive-step-by-step-sum.html
Normal file
44
算法题(国外版)/minimum-value-to-get-positive-step-by-step-sum.html
Normal file
@@ -0,0 +1,44 @@
|
||||
<p>Given an array of integers <code>nums</code>, you start with an initial <strong>positive</strong> value <em>startValue</em><em>.</em></p>
|
||||
|
||||
<p>In each iteration, you calculate the step by step sum of <em>startValue</em> plus elements in <code>nums</code> (from left to right).</p>
|
||||
|
||||
<p>Return the minimum <strong>positive</strong> value of <em>startValue</em> such that the step by step sum is never less than 1.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [-3,2,-3,4,2]
|
||||
<strong>Output:</strong> 5
|
||||
<strong>Explanation: </strong>If you choose startValue = 4, in the third iteration your step by step sum is less than 1.
|
||||
<strong>step by step sum</strong>
|
||||
<strong>startValue = 4 | startValue = 5 | nums</strong>
|
||||
(4 <strong>-3</strong> ) = 1 | (5 <strong>-3</strong> ) = 2 | -3
|
||||
(1 <strong>+2</strong> ) = 3 | (2 <strong>+2</strong> ) = 4 | 2
|
||||
(3 <strong>-3</strong> ) = 0 | (4 <strong>-3</strong> ) = 1 | -3
|
||||
(0 <strong>+4</strong> ) = 4 | (1 <strong>+4</strong> ) = 5 | 4
|
||||
(4 <strong>+2</strong> ) = 6 | (5 <strong>+2</strong> ) = 7 | 2
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2]
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Explanation:</strong> Minimum start value should be positive.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,-2,-3]
|
||||
<strong>Output:</strong> 5
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 100</code></li>
|
||||
<li><code>-100 <= nums[i] <= 100</code></li>
|
||||
</ul>
|
Reference in New Issue
Block a user