当前位置:网站首页>leetcode452. Detonate the balloon with the minimum number of arrows
leetcode452. Detonate the balloon with the minimum number of arrows
2022-07-03 04:57:00 【Day by day, the dish chicken Jie!!】
One : The analects of Confucius
Less self touching , Thank you for your reflection , Always be alert whether you are pretending to work hard , Do you understand Will you What do you want Only myself The clearest
Two : subject
3、 ... and : Upper code
class Solution {
public:
/** Ideas : 1. This problem is similar to non overlapping space , Let's deal with it in ascending order according to the right boundary of each balloon 2. Then we begin to compare the right boundary of the balloon with the left boundary of the next balloon , If it is bigger than it, it can be blasted with the same arrow If it's smaller than that, update the boundary At the same time, the number of bows and arrows is increased by one . */
static bool cmp(const vector<int>& v1,const vector<int>& v2) {
return v1[1] < v2[1];
}
int findMinArrowShots(vector<vector<int>>& points) {
sort(points.begin(),points.end(),cmp);
int temp = points[0][1];// The first right boundary
int count = 1;// The initial value is 1 It means that we need a bow and arrow for the first time
for(int i = 0; i < points.size(); i++) {
if(temp < points[i][0]) {
// If the right boundary of the balloon is smaller than the left boundary of the next balloon , Then add one to the number of bows and arrows
temp = points[i][1];// Also update the right boundary
count++;
}
}
return count;
}
};
边栏推荐
- 文献阅读_基于多模态数据语义融合的旅游在线评论有用性识别研究(中文文献)
- Leetcode simple question: check whether the string is an array prefix
- 普通本科大学生活避坑指南
- Thesis reading_ Chinese medical model_ eHealth
- 关于开学的准备与专业认知
- Introduction to JVM principle
- Market status and development prospect forecast of global button dropper industry in 2022
- 逆袭大学生的职业规划
- Why does I start with =1? How does this code work?
- Current market situation and development prospect forecast of global UV sensitive resin 3D printer industry in 2022
猜你喜欢
Use Sqlalchemy module to obtain the table name and field name of the existing table in the database
MC Layer Target
RT thread flow notes I startup, schedule, thread
[set theory] relational representation (relational matrix | examples of relational matrix | properties of relational matrix | operations of relational matrix | relational graph | examples of relationa
Leetcode simple question: check whether the array is sorted and rotated
Network security textual research recommendation
Kept hot standby and haproxy
The least operation of leetcode simple problem makes the array increment
The usage of micro service project swagger aggregation document shows all micro service addresses in the form of swagger grouping
[XSS bypass - protection strategy] understand the protection strategy and better bypass
随机推荐
Market status and development prospect prediction of the global fire extinguisher industry in 2022
UiPath实战(08) - 选取器(Selector)
《牛客刷verilog》Part II Verilog进阶挑战
Market status and development prospect prediction of the global fire hose industry in 2022
Online VR model display - 3D visual display solution
1103 integer factorization (30 points)
The 19th Zhejiang I. barbecue
【XSS绕过-防护策略】理解防护策略,更好的绕过
The principle is simple, but I don't know how to use it? Understand "contemporaneous group model" in one article
Why does I start with =1? How does this code work?
[PHP vulnerability weak type] basic knowledge, PHP weak equality, error reporting and bypassing
带有注意力RPN和多关系检测器的小样本目标检测网络(提供源码和数据及下载)...
Keepalived热备与HAProxy
Leetcode simple question: check whether the array is sorted and rotated
Market status and development prospect prediction of the global fire alarm sensor industry in 2022
[set theory] binary relation (example of binary relation operation | example of inverse operation | example of composite operation | example of limiting operation | example of image operation)
Caijing 365 stock internal reference: what's the mystery behind the good father-in-law paying back 50 million?
[luatos sensor] 1 light sensing bh1750
编译GCC遇到的“pthread.h” not found问题
Silent authorization login and registration of wechat applet