C++ Simple One-pass, Greedy.


  • 0
    F
    class Solution {
    public:
        int findMinArrowShots(vector<pair<int, int>>& points) {
            if (points.empty()) return 0;
            sort(points.begin(), points.end());
            int last_end = points[0].second, count = 1;
            for (int i = 1; i < points.size(); ++ i)
                if (points[i].first > last_end)
                    last_end = points[i].second, count ++;
                else
                    last_end = min(last_end, points[i].second);
            return count;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.