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)


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