leetcode在力扣 App 中打开
调试中...
调试中...
题目描述
题目描述
题解
题解
提交记录
提交记录
代码
代码
测试用例
测试用例
测试结果
测试结果
中等
相关标签
相关企业
提示

给你一个下标从 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 是 非递减 数组。
通过次数
7.7K
提交次数
19.4K
通过率
40.0%


相关企业

提示 1
To minimize the length of the array, we should maximize the number of operations performed.

提示 2
To perform k operations, it is optimal to use the smallest k values and the largest k values in nums.

提示 3
What is the best way to make pairs from the smallest k values and the largest k values so it is possible to remove all the pairs?

提示 4
If we consider the smallest 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].

提示 5
The greatest possible valid k can be found using binary search.

提示 6
The answer is nums.length - 2 * k.

相似题目

评论 (0)

贡献者
© 2025 领扣网络(上海)有限公司
0 人在线
行 1,列 1
nums =
[1,2,3,4]
Source