Class Solution
java.lang.Object
g2301_2400.s2357_make_array_zero_by_subtracting_equal_amounts.Solution
2357 - Make Array Zero by Subtracting Equal Amounts.<p>Easy</p>
<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><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [1,5,0,3,5]</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong></p>
<p>In the first operation, choose x = 1. Now, nums = [0,4,0,2,4].</p>
<p>In the second operation, choose x = 2. Now, nums = [0,2,0,0,2].</p>
<p>In the third operation, choose x = 2. Now, nums = [0,0,0,0,0].</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [0]</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Explanation:</strong> Each element in nums is already 0 so no operations are needed.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 100</code></li>
<li><code>0 <= nums[i] <= 100</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minimumOperations
public int minimumOperations(int[] nums)
-