当前位置:网站首页>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;
}
};
边栏推荐
- 最大连续子段和(动态规划,递归,递推)
- Notes | numpy-07 Slice and index
- Day 51 - tree problem
- 5-36v input automatic voltage rise and fall PD fast charging scheme drawing 30W low-cost chip
- ZABBIX monitoring of lamp architecture (2): ZABBIX basic operation
- Market status and development prospect prediction of global neutral silicone sealant industry in 2022
- 移动端——uniapp开发记录(公共请求request封装)
- Sdl2 + OpenGL glsl practice (Continued)
- Market status and development prospect prediction of global colorimetric cup cover industry in 2022
- Leetcode simple question: check whether the array is sorted and rotated
猜你喜欢
The reason why the entity class in the database is changed into hump naming
MediaTek 2023 IC written examination approved in advance (topic)
The consumption of Internet of things users is only 76 cents, and the price has become the biggest obstacle to the promotion of 5g industrial interconnection
Oracle SQL table data loss
C language self-made Games: Sanzi (tic tac toe chess) intelligent chess supplement
Do you know UVs in modeling?
[luatos sensor] 2 air pressure bmp180
Three representations of signed numbers: original code, inverse code and complement code
STM32 reverse entry
Compile and decompile GCC common instructions
随机推荐
Shuttle + alluxio accelerated memory shuffle take-off
逆袭大学生的职业规划
Do you know UVs in modeling?
[tools run SQL blind note]
Uipath practice (08) - selector
Objects. Requirenonnull method description
论文阅读_清华ERNIE
1118 birds in forest (25 points)
Automatic voltage rise and fall 5-40v multi string super capacitor charging chip and solution
Market status and development prospect forecast of global heat curing adhesive industry in 2022
[luatos sensor] 1 light sensing bh1750
Market status and development prospects of the global IOT active infrared sensor industry in 2022
Market status and development prospect prediction of the global fire alarm sensor industry in 2022
Notes | numpy-10 Iterative array
1107 social clusters (30 points)
Number of 1 in binary (simple difficulty)
文献阅读_基于多模态数据语义融合的旅游在线评论有用性识别研究(中文文献)
1099 build a binary search tree (30 points)
Thesis reading_ Tsinghua Ernie
Current market situation and development prospect forecast of global UV sensitive resin 3D printer industry in 2022