Skip to content

Latest commit

 

History

History
25 lines (24 loc) · 614 Bytes

File metadata and controls

25 lines (24 loc) · 614 Bytes
  • 按右边界排序,从第一个右边界开始射箭,计算能引爆的气球数量,不能引爆时再换成下一个未引爆的气球的右边界
class Solution {
 public:
  int findMinArrowShots(vector<vector<int>>& points) {
    if (empty(points)) {
      return 0;
    }
    sort(begin(points), end(points),
         [](vector<int>& x, vector<int>& y) { return x[1] < y[1]; });
    int res = 1;
    int t = points[0][1];
    for (auto& x : points) {
      if (t >= x[0] && t <= x[1]) {
        continue;
      } else {
        t = x[1];
        ++res;
      }
    }
    return res;
  }
};