代码随想录:用最少的箭引爆气球

class Solution {
public:
    static bool cmp(vector<int> a, vector<int> b) {
        if (a[0] == b[0]) {
            return a[1] < b[1];
        }
        return a[0] < b[0];
    }

    int findMinArrowShots(vector<vector<int>>& points) {
        sort(points.begin(), points.end(), cmp);
        int res = 1;
        int right = points[0][1];
        for (int i = 1; i < points.size(); i++) {
            if (points[i][0] > right) {
                res++;
                right = points[i][1];
            }else{
                right = min(right,points[i][1]);
            }
        }
        return res;
    }
};
posted @ 2025-02-05 16:47  huigugu  阅读(6)  评论(0)    收藏  举报