当前位置:网站首页>LeetCode 1673. Find the most competitive subsequence**
LeetCode 1673. Find the most competitive subsequence**
2022-06-11 00:14:00 【Evening rain forest bell】
Specific ideas :
and 321 The problem is the same as the solution ;
Is the precursor scheme ;
It is equivalent to finding a minimum non strict ascending sequence , Keep front-end elements as small as possible ;
index Represents the number of bits saved ;
remain Represents the number to be deleted ;
So pass remain To make sure , If you want to keep the front-end elements as small as possible , How many can be deleted at most ;
Specific code :
class Solution {
public:
vector<int> mostCompetitive(vector<int>& nums, int k) {
int n=nums.size();
vector<int>st;
int remain=n-k;
int index=0;
for(int i=0;i<nums.size();i++){
while(!st.empty()&&nums[i]<*st.rbegin()&&remain>0){
index--;
remain--;
st.pop_back();
}
if(index<k){
st.push_back(nums[i]);
index++;
}else{
remain--;
}
}
return st;
}
};
//2,3,3,4,6
边栏推荐
- It is said that the verification code is a barrier in the crawler. I can break through it with only five lines of code.
- VTK example -- three intersecting planes
- Hyperleger fabric installation
- MD5Util
- Basic operation of OpenCV actual combat image: this effect amazed everyone (with code analysis)
- 【Pygame合集】滴~穿越童年游戏指南 请查收:这里面有你玩过的游戏嘛?(附五款源码自取)
- [turtle confessions collection] "the moon at the bottom of the sea is the moon in the sky, and the person in front of us is the sweetheart." Be happy for the rest of your life, and be safe for ever ~
- Quick sort
- Leetcode-15 sum of three numbers
- [opencv practice] in cold winter, there will be a rainbow. Do you love this special effect?
猜你喜欢
![[opencv practice] this seal](/img/f4/c6a4529b8b24773bcb39b4d2c6e16f.png)
[opencv practice] this seal "artifact" is awesome, saving time and improving efficiency. It is powerful ~ (complete source code attached)

Njupt South Post collection_ Experiment 2

SystemVerilog (x) - user defined type

【颜值检测神器】来,请拿出你们的绝活(这颜值,对得起观众么?)
![[appearance detection artifact] come on, please show me your unique skill (is this appearance worthy of the audience?)](/img/c4/b571bec5fe0cd2968e078a8231d0bd.png)
[appearance detection artifact] come on, please show me your unique skill (is this appearance worthy of the audience?)
![[pyGame collection] memory killing -](/img/97/10a4333662b49ac35e5b7433a5e6a4.png)
[pyGame collection] memory killing - "Childhood Games", how many shots did you get? (attach five source codes for self access)
![[pyGame games] tank battle, how many childhood games do you remember?](/img/30/951fdbb944e026701af08c0c068cd8.png)
[pyGame games] tank battle, how many childhood games do you remember?

【Turtle表白合集】“海底月是天上月,眼前人是心上人。”余生多喜乐,长平安~(附3款源码)

Njuptn Nanyou Discrete Mathematics_ Experiment 4

Judgment and other issues: how to determine whether the judgment of the procedure is correct?
随机推荐
MP框架基本操作(自用)
VTK例子--三个相交的平面
Njupt South Post collection_ Experiment 2
[pyGame games] interesting puzzle game: how many hamsters can you play? (source code attached)
MultipartFile重命名上传
【Pygame小遊戲】別找了,休閑遊戲專題來了丨泡泡龍小程序——休閑遊戲研發推薦
[pyGame games] don't look for it. Here comes the leisure game topic - bubble dragon widget - recommendation for leisure game research and development
Leetcode-560 and subarray with K
Basic introduction and core components of kubernetes
[pyGame] this "groundhog" game is going to be popular (come on, come on)
[auto reply Script] happy new year. I typed every word myself, not forwarded it~
[pyGame games] story stream recommendation: what kind of games can you like? (devil lover, bully's wife version)
Lambda learning records
【Pygame小游戏】别找了,休闲游戏专题来了丨泡泡龙小程序——休闲游戏研发推荐
数据库表结构
About optimizing API interface response speed
[JVM] thread
什么是绝对和相对路径,有哪些优缺点?
Excel单元格
[daily] robots Txt allow all search engines to include