simple C++ greedy, easy to understand


  • 0
    B

    '''
    int findMinArrowShots(vector<pair<int, int>>& points) {
    if (points.size() == 0) return 0;
    sort(points.begin(), points.end(), [](pair<int, int> p1, pair<int, int> p2){return p1.first == p2.first ? p1.second < p2.second : p1.first < p2.first; });
    int res = 1;
    int end = points[0].second;
    for (int i = 1; i < points.size();i++)
    {
    if (points[i].first > end)
    {
    res++;
    end = points[i].second;
    }
    else
    {
    end = min(end, points[i].second);
    }
    }
    return res;
    }
    '''


Log in to reply
 

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