public static List<Interval> insert(List<Interval> intervals, Interval newInterval) {
    	intervals.add(0, newInterval);
    	int index = 0;
    	for (int i = 1; i < intervals.size(); i++) {
    		Interval idx = intervals.get(index);
    		Interval cur = intervals.get(i);
    		if (idx.end < cur.start) continue;
    		if (idx.start > cur.end) {
    			Interval t = intervals.remove(index);
    			intervals.add(i, t);
    			index = i;
    			continue;
    		}
    		if (idx.start > cur.start) {
	    		if (idx.end >= cur.end && idx.start <= cur.end) {
	    			Interval val = new Interval(cur.start, idx.end);
	    			intervals.add(i, val);
	    			intervals.remove(i + 1);
	    			intervals.remove(index);
	    			index = i - 1;
	    			i--;
	    		} else {
	    			intervals.remove(index);
	    			index = i - 1;
	    			i--;
	    		}
    		} else {
    			if (idx.end >= cur.end) {
    				intervals.remove(i);
    				i--;
    			} else {
    				Interval val = new Interval(idx.start, cur.end);
    				intervals.add(i, val);
    				intervals.remove(i + 1);
    				intervals.remove(index);
    				index = i - 1;
    				i--;
    			}
    		}
    	}
        return intervals;
    }