mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
37 lines
1.3 KiB
HTML
37 lines
1.3 KiB
HTML
<p>You are given a non-negative integer array <code>nums</code>. In one operation, you must:</p>
|
|
|
|
<ul>
|
|
<li>Choose a positive integer <code>x</code> such that <code>x</code> is less than or equal to the <strong>smallest non-zero</strong> element in <code>nums</code>.</li>
|
|
<li>Subtract <code>x</code> from every <strong>positive</strong> element in <code>nums</code>.</li>
|
|
</ul>
|
|
|
|
<p>Return <em>the <strong>minimum</strong> number of operations to make every element in </em><code>nums</code><em> equal to </em><code>0</code>.</p>
|
|
|
|
<p> </p>
|
|
<p><strong>Example 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> nums = [1,5,0,3,5]
|
|
<strong>Output:</strong> 3
|
|
<strong>Explanation:</strong>
|
|
In the first operation, choose x = 1. Now, nums = [0,4,0,2,4].
|
|
In the second operation, choose x = 2. Now, nums = [0,2,0,0,2].
|
|
In the third operation, choose x = 2. Now, nums = [0,0,0,0,0].
|
|
</pre>
|
|
|
|
<p><strong>Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> nums = [0]
|
|
<strong>Output:</strong> 0
|
|
<strong>Explanation:</strong> Each element in nums is already 0 so no operations are needed.
|
|
</pre>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>1 <= nums.length <= 100</code></li>
|
|
<li><code>0 <= nums[i] <= 100</code></li>
|
|
</ul>
|