-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.cpp
More file actions
42 lines (33 loc) · 876 Bytes
/
solution.cpp
File metadata and controls
42 lines (33 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// Created by mingyi on 19.04.20.
//
#include <vector>
#include <algorithm>
#include <cassert>
using namespace std;
int findMinArrowShots(vector<vector<int>> &points) {
if (points.empty()) {
return 0;
}
sort(points.begin(), points.end(), [](const vector<int> &itv1, const vector<int> &itv2) {
return itv1[1] < itv2[1];
});
int cnt {1};
int end {points[0][1]};
for (int i = 1; i < points.size(); i++) {
if (points[i][0] > end) {
cnt++;
end = points[i][1];
}
}
return cnt;
}
int main() {
vector<vector<int>> points1 {{10, 16}, {2, 8}, {1, 6}, {7, 12}};
assert(2 == findMinArrowShots(points1));
vector<vector<int>> points2 {{-1, 1}, {0, 1}, {2, 3}, {1, 2}};
assert(2 == findMinArrowShots(points2));
vector<vector<int>> points3 {{-2147483648,2147483647}};
assert(1 == findMinArrowShots(points3));
return 0;
}