给你一个下标从 0 开始的 非递减 整数数组 nums
。
你可以执行以下操作任意次:
i
和 j
,满足 nums[i] < nums[j]
。nums
中下标在 i
和 j
处的元素删除。剩余元素按照原来的顺序组成新的数组,下标也重新从 0 开始编号。请你返回一个整数,表示执行以上操作任意次后(可以执行 0 次),nums
数组的 最小 数组长度。
示例 1:
输入:nums = [1,2,3,4]
输出:0
解释:
示例 2:
输入:nums = [1,1,2,2,3,3]
输出:0
解释:
示例 3:
输入:nums = [1000000000,1000000000]
输出:2
解释:
由于两个数字相等,不能删除它们。
示例 4:
输入:nums = [2,3,4,4,4]
输出:1
解释:
提示:
1 <= nums.length <= 105
1 <= nums[i] <= 109
nums
是 非递减 数组。k
operations, it is optimal to use the smallest k
values and the largest k
values in nums
.k
values and the largest k
values so it is possible to remove all the pairs?k
values and the largest k
values as two separate sorted 0-indexed arrays, a
and b
, It is optimal to pair a[i]
and b[i]
. So, a k
is valid if a[i] < b[i]
for all i
in the range [0, k - 1]
.k
can be found using binary search.nums.length - 2 * k
.