Nlog(n) passed all test cases......???


  • 1
    N

    sort(num.begin(),num.end());
    int i,l = num.size();
    int count,max_ = 0;

        for(i=0,count = 1;i<l;++i){
            if(num[i+1] == (num[i]+1))
                count++;
            else if(num[i+1] == num[i])
                continue;
            else{
                if(max_<count)
                    max_ = count;
                count = 1;
            }
        }
        if(max_<count)
            max_ = count;
        return max_;

Log in to reply
 

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