Minimum Number of Arrows to Burst Balloons LeetCode solution in C++

1
class Solution {
2
public:
3
static bool cmp(vector<int> &a, vector<int> &b) {
4
return a[1] < b[1];
5
}
6
int findMinArrowShots(vector<vector<int>> &points) {
7
sort(points.begin(), points.end(), cmp);
8
// burst the first ballon at least
9
int arrow = 1;
10
int end = points[0][1];
11
for (int i = 1; i < points.size(); i++) {
12
// start time of other interval is greater than current end time means we
13
// need one more arrow for bursting it
14
if (points[i][0] > end) {
15
arrow++;
16
end = points[i][1];
17
}
18
}
19
return arrow;
20
}
21
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0