当前位置:网站首页>LeetCode 1996. 游戏中弱角色的数量*
LeetCode 1996. 游戏中弱角色的数量*
2022-06-10 22:57:00 【暮雨林钟】
具体思路:
之前见过一道原题;
卡在了单调栈上的第二维度排序上;
具体代码:
1.单调栈:
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.排序方法:
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;
}
};
边栏推荐
- SQL statement -- enter the month, query the date (month, year, day), and output the month
- [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 ~
- Excel cell
- Things about Bluetooth development (10) -- getting to know ble for the first time
- Qt客户端套接字QTcpSocket通过bind指定本地ip
- MySQL command line import and export data
- [auto reply or remind assistant] Mom doesn't have to worry about me missing messages any more (10 Line Code Series)
- [mathematics] [continuum mechanics] symmetry tensor, strain tensor and stress tensor in fluid mechanics
- 【自动回复小脚本】新年快乐,每一个字都是我亲自手打的,不是转发哦~
- Judgment and other issues: how to determine whether the judgment of the procedure is correct?
猜你喜欢
![[pyGame] when the](/img/7e/d2cd2eb2fff2c1fb2b41f579d4f70e.png)
[pyGame] when the "coolest snake in history" arrives, fun will play it (no money for fun)

Hyperleger fabric installation

Bluetooth development (11) -- ble interacts happily
![[pyGame collection] please check the game guide through childhood: are there any games you have played? (attach five source codes for self access)](/img/f8/e71a1524f73364053952099e7b9588.png)
[pyGame collection] please check the game guide through childhood: are there any games you have played? (attach five source codes for self access)

【Pygame合集】滴~穿越童年游戏指南 请查收:这里面有你玩过的游戏嘛?(附五款源码自取)

【漫天烟花】绚烂烟花点亮夜空也太美了叭、某程序员携带烟花秀给大家拜年啦~

【JVM】线程

【JVM】类加载机制

Easyrecovery15 simple and convenient data recovery tool

From the perspective of Confucius Temple IP crossover, we can see how the six walnuts become "butterflies" for the second time
随机推荐
Bluetooth development (4) -- about flow control
Unity自定义文件夹图标颜色 个性化Unity编译器
Excel单元格
It is said that the verification code is a barrier in the crawler. I can break through it with only five lines of code.
[pyGame] can the little dinosaur on chrome be played with code? It looks like fun~
[pyGame games] tank battle, how many childhood games do you remember?
【Pygame小游戏】别找了,休闲游戏专题来了丨泡泡龙小程序——休闲游戏研发推荐
【Pygame小游戏】趣味益智游戏 :打地鼠,看一下能打多少只呢?(附源码)
C language file operation
mysql 数据库 表 备份
Is the financial management of qiniu school reliable and safe
Qt客户端套接字QTcpSocket通过bind指定本地ip
[mathematics] [continuum mechanics] symmetry tensor, strain tensor and stress tensor in fluid mechanics
[JVM] memory model
【Turtle表白合集】“海底月是天上月,眼前人是心上人。”余生多喜乐,长平安~(附3款源码)
B 树的简单认识
Typecho website speed optimization - Xingze V Club
After deepin20 menu startup option, the self-test indicates that iwlwwifi is stopped
[database] types of NoSQL database
插入排序