c++ greedy


  • 0
    J

    '''

    int findMinArrowShots(vector<pair<int, int>>& points) {
        if (points.size() == 0) return 0;
        sort(points.begin(), points.end());
        pair<int, int> cur = make_pair(INT_MIN, INT_MAX);
        int ret = 0;
        for (int i = 0; i < points.size(); i++)
        {
            if (points[i].first <= cur.second)
            {
                cur = make_pair(points[i].first, min(cur.second, points[i].second));
            }else
            {
                ret++;
                cur = points[i];
            }
        }
        
        return ret + 1;
    }
    

    '''


Log in to reply
 

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