调试中...
调试中...
题目描述
题目描述
题解
题解
提交记录
提交记录
代码
代码
测试用例
测试用例
测试结果
测试结果
困难
相关标签
相关企业
提示

给你一个包含若干 互不相同 整数的数组 nums ,你需要执行以下操作 直到数组为空 :

  • 如果数组中第一个元素是当前数组中的 最小值 ,则删除它。
  • 否则,将第一个元素移动到数组的 末尾 。

请你返回需要多少个操作使 nums 为空。

 

示例 1:

输入:nums = [3,4,-1]
输出:5
OperationArray
1[4, -1, 3]
2[-1, 3, 4]
3[3, 4]
4[4]
5[]

 

示例 2:

输入:nums = [1,2,4,3]
输出:5
OperationArray
1[2, 4, 3]
2[4, 3]
3[3, 4]
4[4]
5[]

 

示例 3:

输入:nums = [1,2,3]
输出:3
OperationArray
1[2, 3]
2[3]
3[]

 

提示:

  • 1 <= nums.length <= 105
  • -10<= nums[i] <= 109
  • nums 中的元素 互不相同 。
通过次数
3.3K
提交次数
8.2K
通过率
40.4%


相关企业

提示 1
Understand the order in which the indices are removed from the array.

提示 2
We don’t really need to delete or move the elements, only the array length matters.

提示 3
Upon removing an index, decide how many steps it takes to move to the next one.

提示 4
Use a data structure to speed up the calculation.

评论 (0)

贡献者
© 2025 领扣网络(上海)有限公司
0 人在线
行 1,列 1
运行和提交代码需要登录
nums =
[3,4,-1]
Source