当前位置:网站首页>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
边栏推荐
- Easyrecovery15 simple and convenient data recovery tool
- Openresty installation
- 【Pygame合集】回忆杀-“童年游戏”,看看你中几枪?(附五款源码自取)
- Error report of curl import postman
- Shell Sort
- [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~
- SystemVerilog (x) - user defined type
- 【JVM】内存模型
- Leetcode-15 sum of three numbers
猜你喜欢
![[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小游戏】首月破亿下载 一款高度融合了「超休闲游戏特性」的佳作~
![[JVM] garbage collection mechanism](/img/61/e7611380954cdcd316dd0e570bdf17.png)
[JVM] garbage collection mechanism

yum源更新
![[turtle confessions collection]](/img/81/b4bacc23691e58e403f1330d0ca7cf.jpg)
[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 ~

VTK例子--三个相交的平面

Njupt Nanyou Discrete Mathematics_ Experiment 2

763. 划分字母区间

Basic introduction and core components of kubernetes

Hyperleger fabric installation
随机推荐
Go语言Channel理解使用
Excel单元格
[JVM] garbage collection mechanism
VTK example -- three intersecting planes
博文推荐|构建 IoT 应用——FLiP 技术栈简介
Basic introduction and core components of kubernetes
[pyGame games] I'm not afraid you can't walk the maze series: the ultimate AI walks the maze. After learning, it will take you to open the door to a new world ~ (with game source code)
Bluetooth (5) -- about retransmission
[pyGame collection] memory killing - "Childhood Games", how many shots did you get? (attach five source codes for self access)
From the perspective of Confucius Temple IP crossover, we can see how the six walnuts become "butterflies" for the second time
Njuptn Nanyou Discrete Mathematics_ Experiment 4
Njupt Nanyou Discrete Mathematics_ Experiment 3
Exemple VTK - - trois plans qui se croisent
【Pygame小游戏】剧情流推荐:什么样的游戏才能获得大家的喜欢呢?(魔鬼恋人、霸总娇妻版)
【自动回复or提醒小助手】妈妈再也不用担心我漏掉消息了(10行代码系列)
【Turtle表白合集】“海底月是天上月,眼前人是心上人。”余生多喜乐,长平安~(附3款源码)
[daily] robots Txt allow all search engines to include
From the perspective of Confucius Temple IP crossover, we can see how the six walnuts become "butterflies" for the second time
【AI出牌器】第一次见这么“刺激”的斗地主,胜率高的关键因素竟是......
[pyGame games] don't look for it. Here comes the leisure game topic - bubble dragon widget - recommendation for leisure game research and development