a problem need to be solved


  • 0
    E

    when test the case:[[1,2147483647]]
    Runtime Error happend
    can you give me some reasons?

    class Solution {
    public:
        static bool cmp(const pair<int,int>& p1,const pair<int,int>& p2){
            if(p1.second<p2.second)return true;
            if(p1.second==p2.second&&p1.first<p2.first)return true;
            return false;
        }
        
        int findMinArrowShots(vector<pair<int, int>>& points) {
            if(points.size()==0)return 0;
            if(points.size()==1)return 1;
            // for(int k =0;k<points.size();k++){
            //     int m = k;
            //     for(int l = k+1;l<points.size();l++){
            //         if(points[l][1]<points[m][1]||(points[l][1]==points[m][1]&&points[l][0]<points[m][0])){
            //             m=k;
            //         }
            //     }
            //     swap(points[m],points[k]);
            // }
            
            sort(points.begin(),points.end(),cmp);
            int _cou =0,i=0,j=0;
            while(i<points.size()){
                j = i+1;
                while(points[i].second>=points[j].first){
                    j++;
                }
                _cou++;
                i=j;
            }
            return _cou;
            
        }
    };
    

Log in to reply
 

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