C++ O(nlogn) solution in 8 lines


  • 3
    P
    int findMinArrowShots(vector<pair<int, int>>& points) {
        int res = 0, i = 0, temp;
        sort(points.begin(), points.end(), [](pair<int, int> a, pair<int, int> b){return a.second < b.second;});
        while (i < points.size()) {
            res++;
            temp = points[i++].second;
            while (i < points.size() && points[i].first <= temp) i++;
        }
        return res;
    }

  • 1
    C

    it's a O(nlogn) solution cause you use sort in your algorithm


Log in to reply
 

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