C++ solution for Minimum Number of Arrows to Burst Balloons


  • 0
    G
    class Solution {
    private:
        struct comp{
            bool operator()(pair<int,int> p1, pair<int,int> p2){
                return p1.first<p2.first;
            }
        }comp;
    public:
        int findMinArrowShots(vector<pair<int, int>>& points) {
            sort(points.begin(),points.end(),comp);//
            int result=0;
            int index=INT_MIN;
            for(int i=0;i<points.size();i++){
                if(points[i].first<=index&&points[i].first!=INT_MIN){
                    index=min(index,points[i].second);
                    continue;
                }
                result++;
                index=points[i].second;
            }
            return result;
        }
    };

Log in to reply
 

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