当前位置:网站首页>LeetCode 1996. Number of weak characters in the game*
LeetCode 1996. Number of weak characters in the game*
2022-06-11 00:14:00 【Evening rain forest bell】
Specific ideas :
I have seen an original question before ;
Stuck in the second dimension sorting on the monotone stack ;
Specific code :
1. Monotonic stack :
class Solution {
public:
int numberOfWeakCharacters(vector<vector<int>>& properties) {
int n=properties.size();
vector<int>arr;
sort(properties.begin(),properties.end(),[](vector<int>& a,vector<int>& b){
if(a[0]==b[0])
return a[1]>b[1];
else
return a[0]<b[0];
});
for(int i=0;i<n;i++){
arr.push_back(properties[i][1]);
}
stack<int>st;
int cnt=0;
for(int i=0;i<arr.size();i++){
while(!st.empty()&&arr[st.top()]<arr[i]){
int index=st.top();
st.pop();
cnt++;
}
st.push(i);
}
return cnt;
}
};
2. Sorting method :
class Solution {
public:
int numberOfWeakCharacters(vector<vector<int>>& properties) {
int n=properties.size();
vector<int>arr;
sort(properties.begin(),properties.end(),[](vector<int>& a,vector<int>& b){
if(a[0]==b[0])
return a[1]<b[1];
else
return a[0]>b[0];
});
int maxdef=0;
int cnt=0;
for(int i=0;i<properties.size();i++){
if(maxdef>properties[i][1]){
cnt++;
}
maxdef=max(maxdef,properties[i][1]);
}
return cnt;
}
};
边栏推荐
- MultipartFile重命名上传
- JVM 垃圾回收机制和常见的垃圾回收器
- [pyGame] can the little dinosaur on chrome be played with code? It looks like fun~
- 【Opencv实战】这个印章“神器”够牛,节省了时间提高了效率,厉害~(附完整源码)
- B 树的简单认识
- Exemple VTK - - trois plans qui se croisent
- Njupt South Post collection_ Experiment 1
- Compared with the "South-to-North Water Transfer", what will the "east to west" of the fire bring to cloud computing?
- WinDriver compilation summary
- ASP. Net programming version C (notes along with learning progress)
猜你喜欢

【Pygame小游戏】剧情流推荐:什么样的游戏才能获得大家的喜欢呢?(魔鬼恋人、霸总娇妻版)

Leetcode-15 sum of three numbers
![[auto reply or remind assistant] Mom doesn't have to worry about me missing messages any more (10 Line Code Series)](/img/b3/64429247ee1b91a05d4faa1d78a1df.png)
[auto reply or remind assistant] Mom doesn't have to worry about me missing messages any more (10 Line Code Series)

【自动回复小脚本】新年快乐,每一个字都是我亲自手打的,不是转发哦~

【Pygame小游戏】这款“打地鼠”小游戏要火了(来来来)
![[auto reply Script] happy new year. I typed every word myself, not forwarded it~](/img/53/75d2bbbee653a41e206ebd751fdea1.png)
[auto reply Script] happy new year. I typed every word myself, not forwarded it~

From the perspective of Confucius Temple IP crossover, we can see how the six walnuts become "butterflies" for the second time

【Pygame小游戏】激荡大脑思维,一起来玩转奇思妙想“24点”叭~(超赞滴)

452. 用最少数量的箭引爆气球

【 pygame Games 】 don't find, Leisure Games Theme come 丨 Bubble Dragon applet - - Leisure Games Development recommendation
随机推荐
安全生产月,黄埔开展燃气安全进商铺宣传活动
Bluetooth development (9) -- A2DP protocol in combination with code
【Pygame小游戏】激荡大脑思维,一起来玩转奇思妙想“24点”叭~(超赞滴)
Go语言Channel理解使用
[auto reply or remind assistant] Mom doesn't have to worry about me missing messages any more (10 Line Code Series)
[daily] robots Txt allow all search engines to include
SQL查询,子查询作为结果字段
【Pygame小游戏】这款经典的炸弹人超能游戏上线,你爱了嘛?(附源码)
[JVM] garbage collection mechanism
什么是绝对和相对路径,有哪些优缺点?
【数据库】Nosql数据库的种类
After deepin20 menu startup option, the self-test indicates that iwlwwifi is stopped
Is the financial management of qiniu school reliable and safe
【Turtle表白合集】“海底月是天上月,眼前人是心上人。”余生多喜乐,长平安~(附3款源码)
Quick sort
【 pygame Games 】 don't find, Leisure Games Theme come 丨 Bubble Dragon applet - - Leisure Games Development recommendation
763. 划分字母区间
Typecho website speed optimization - Xingze V Club
【AcWing】4. Multiple knapsack problem I
mysql 数据库 表 备份