You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// case 1: add org// org: ----// new: ==// case 2: add new, add org// org: ----// new: ==// case 3: add nothing, revise new // org: -------...// new: =====...// key point: use newInterval to cover original interval, modify the new intervalpublicList<Interval> insert(List<Interval> intervals, IntervalnewI) {
List<Interval> res = newArrayList<>();
for(Intervali: intervals) {
if(newI==null || i.end < newI.start) { //newInterval has been merged or newInteval is not come yetres.add(i);
}elseif(newI.end<i.start){//newInterval should be added, current interval should be addres.add(newI);
newI = null;
res.add(i);
}else { // newInterval is not end yet, keep searching nextnewI.start = Math.min(newI.start, i.start);
newI.end = Math.max(newI.end,i.end);
}
}
if(newI!=null) res.add(newI);
returnres;
}