本题可以使用单调栈解决。
对于每个元素 nums[i],我们需要判断它会在第几轮被删除。
从左到右遍历数组,维护一个单调递减趋势相关的栈,栈中保存:
给定一个长度为 n 的整数数组 nums。
在一步操作中,需要同时移除所有满足 nums[i−1]>nums[i] 的元素 nums[i],其中 1<=i<n。
重复执行上述操作,直到数组 nums 变为非递减数组。
Scan the QR code below with WeChat to sign in
First-time scan will create your account automatically
请使用微信扫描下方二维码完成注册