leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0452.cpp (473B)


0 class Solution {
1 typedef vector<int> segment;
3 public:
4 int findMinArrowShots(vector<segment> &segments) {
5 auto cmp = [](const segment &a, const segment &b) { return a[1] < b[1]; };
6 sort(segments.begin(), segments.end(), cmp);
7 int res = 1, arrow = segments[0][1];
8 for (segment &s : segments) {
9 if (s[0] > arrow) {
10 res++;
11 arrow = s[1];
12 }
13 }
14 return res;
15 }
16 };