Class Solution
java.lang.Object
g1501_1600.s1558_minimum_numbers_of_function_calls_to_make_target_array.Solution
1558 - Minimum Numbers of Function Calls to Make Target Array.<p>Medium</p>
<p>You are given an integer array <code>nums</code>. You have an integer array <code>arr</code> of the same length with all values set to <code>0</code> initially. You also have the following <code>modify</code> function:</p>
<p><img src="https://assets.leetcode.com/uploads/2020/07/10/sample_2_1887.png" alt="" /></p>
<p>You want to use the modify function to covert <code>arr</code> to <code>nums</code> using the minimum number of calls.</p>
<p>Return <em>the minimum number of function calls to make</em> <code>nums</code> <em>from</em> <code>arr</code>.</p>
<p>The test cases are generated so that the answer fits in a <strong>32-bit</strong> signed integer.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [1,5]</p>
<p><strong>Output:</strong> 5</p>
<p><strong>Explanation:</strong> Increment by 1 (second element): [0, 0] to get [0, 1] (1 operation).</p>
<p>Double all the elements: [0, 1] -> [0, 2] -> [0, 4] (2 operations).</p>
<p>Increment by 1 (both elements) [0, 4] -> [1, 4] -> <strong>[1, 5]</strong> (2 operations).</p>
<p>Total of operations: 1 + 2 + 2 = 5.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [2,2]</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> Increment by 1 (both elements) [0, 0] -> [0, 1] -> [1, 1] (2 operations).</p>
<p>Double all the elements: [1, 1] -> <strong>[2, 2]</strong> (1 operation).</p>
<p>Total of operations: 2 + 1 = 3.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> nums = [4,2,5]</p>
<p><strong>Output:</strong> 6</p>
<p><strong>Explanation:</strong> (initial)[0,0,0] -> [1,0,0] -> [1,0,1] -> [2,0,2] -> [2,1,2] -> [4,2,4] -> <strong>[4,2,5]</strong>(nums).</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>0 <= nums[i] <= 10<sup>9</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minOperations
public int minOperations(int[] nums)
-