missing test case


  • 0

    @1337c0d3r My following wrong code passed

        vector<Interval> insert(vector<Interval>& intervals, Interval newInterval) {
            vector<Interval> res;
            for(auto &i:intervals) {
                if(i.end < newInterval.start) res.push_back(i);
                else if (i.start > newInterval.end) {
                    res.push_back(newInterval);
                    res.push_back(i);
                    newInterval.start = INT_MAX;
                    newInterval.end = INT_MIN;
                } else {
                    newInterval.start = min(i.start,newInterval.start);
                    newInterval.end = max(i.end,newInterval.end);
                } 
            }
            if(newInterval.start <= newInterval.end) res.push_back(newInterval);
            return res;
        }
    

    I have a hack using INT_MAX and it won't work if the input contains INT_MAX.
    For example, input
    [[1,5],[10,11],[15,2147483647]]
    [5,7]
    my answer
    [[1,7],[10,11],[2147483647,-2147483648],[15,2147483647]]
    Expected answer
    [[1,7],[10,11],[15,2147483647]]


  • 0

    @yu6 Thanks, I've just added your test case.


Log in to reply
 

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