Getting Compile error : void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator)'


  • 0
    T

    /**

    • Definition for an interval.

    • struct Interval {

    • int start;
      
    • int end;
      
    • Interval() : start(0), end(0) {}
      
    • Interval(int s, int e) : start(s), end(e) {}
      
    • };
      */
      class Solution
      {
      public:

       vector<Interval> ans;
       
       vector<Interval> merge(vector<Interval> &inter) 
       {
           sort(inter.begin(),inter.end());
           int n=(int)inter.size();
           struct Interval prev=inter[0];
           for(int curr=1;curr<n;curr++)
           {
               if(inter[curr].start <= prev.end)
               {
                   struct Interval merged;
                   merged.start=prev.start;
                   merged.end=max(prev.end,inter[curr].end);
                   prev=merged;
               }
               else
               {
                   ans.push_back(prev);
                   prev=inter[curr];
               }
           }
           ans.push_back(prev);
           
           return ans;
       }
      

    };


  • 0
    J

    You should provide a comparision function for Interval type. The compiler doesn't know how to deal with custom types.


Log in to reply
 

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