Why run error? what's the problem whih"intervals.size()<=1"?


  • 0
    L
         class Solution {
          public:
                static bool comp(const Interval& a, const Interval& b){
                   return a.start < b.start;
                }
              vector<Interval> merge(vector<Interval> &intervals) {
                         vector<Interval> intervals2;
                         if(intervals.size()<=1){
                                return intervals;  }
                        sort(intervals.begin(), intervals.end(), comp);
                        intervals2.push_back(intervals[0]);
                     for(int i = 1; i < intervals.size();++i){
    	
    			Interval up = intervals2[intervals2.size()-1];
    			Interval down = intervals[i];
    		
    			if(up.end >= down.start)
    			{
    				int ma = max(up.end,down.end);
    				intervals2[intervals2.size()-1].end = ma;
    			}
    			else{
    				
    				intervals2.push_back(down);
    			}
    	         }
                     }
        };

Log in to reply
 

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