Class Solution
- java.lang.Object
-
- g2001_2100.s2009_minimum_number_of_operations_to_make_array_continuous.Solution
-
public class Solution extends Object
2009 - Minimum Number of Operations to Make Array Continuous.Hard
You are given an integer array
nums. In one operation, you can replace any element innumswith any integer.numsis considered continuous if both of the following conditions are fulfilled:- All elements in
numsare unique. - The difference between the maximum element and the minimum element in
numsequalsnums.length - 1.
For example,
nums = [4, 2, 5, 3]is continuous , butnums = [1, 2, 3, 5, 6]is not continuous.Return the minimum number of operations to make
numscontinuous.Example 1:
Input: nums = [4,2,5,3]
Output: 0
Explanation: nums is already continuous.
Example 2:
Input: nums = [1,2,3,5,6]
Output: 1
Explanation: One possible solution is to change the last element to 4. The resulting array is [1,2,3,5,4], which is continuous.
Example 3:
Input: nums = [1,10,100,1000]
Output: 3
Explanation: One possible solution is to:
-
Change the second element to 2.
-
Change the third element to 3.
-
Change the fourth element to 4.
The resulting array is [1,2,3,4], which is continuous.
Constraints:
1 <= nums.length <= 1051 <= nums[i] <= 109
- All elements in
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intminOperations(int[] nums)
-