SHARE
TWEET

Untitled

a guest Jun 19th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static ArrayList<Interval> insertRange(ArrayList<Interval> intervalsList, Interval insert) {
  2.     ArrayList<Interval> out = new ArrayList<>();
  3.     for(Interval i: intervalsList){
  4.         if(i.end < insert.start) {
  5.             out.add(i);
  6.         }
  7.         else if(i.start > insert.end) {
  8.             out.add(insert);
  9.             insert = i;
  10.         }
  11.         else if(i.start <= insert.end || i.end >= insert.start){
  12.             int newStart = Math.min(i.start, insert.start);
  13.             int newEnd = Math.max(i.end, insert.end);
  14.             insert = new Interval(newStart, newEnd);
  15.         }
  16.     }
  17.     out.add(insert);
  18.     return out;
  19. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top