Simple C-code


  • 0
    L

    Simple Code in C
    '''
    #include <stdlib.h>
    int cmpfunc(const void* p , const void* q)
    {
    int l = ((struct Interval *)p)->end;
    int r = ((struct Interval *)q)->end;
    return (l-r);
    }

    int eraseOverlapIntervals(struct Interval* intervals, int intervalsSize) {
    int i,count=1;
    if(intervalsSize==1|| intervalsSize==0)
    return 0;
    qsort(intervals,intervalsSize, 8 , &cmpfunc);
    int end = (intervals+0)->end;
    for(i=0;i<intervalsSize;++i)
    {
    if((intervals+i)->start >= end)
    {
    end = ((intervals+i)->end);
    ++count;
    }
    }
    return (intervalsSize-count);
    }
    '''


Log in to reply
 

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