Skip to content

Commit 495b189

Browse files
authored
Create 452. Minimum Number of Arrows to Burst Balloons.cpp
1 parent db9078c commit 495b189

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
public:
3+
4+
static bool comp(const vector<int>& vec1, const vector<int>& vec2)
5+
{
6+
return vec1[1] < vec2[1];
7+
}
8+
9+
int findMinArrowShots(vector<vector<int>>& points)
10+
{
11+
if (points.size() <= 1)
12+
return points.size();
13+
14+
sort(points.begin(), points.end(), comp);
15+
16+
int minNumArrow = 0;
17+
int tmp = points[0][1];
18+
19+
for (int i = 1; i < points.size(); i++)
20+
{
21+
minNumArrow += points[i][0] > tmp;
22+
tmp = points[i][0] > tmp ? points[i][1] : tmp;
23+
}
24+
25+
return minNumArrow + 1;
26+
}
27+
};

0 commit comments

Comments
 (0)