public List<Interval> merge(List<Interval> intervals) {
		if (intervals == null || intervals.size() < 2)
			return intervals;
		// First need to sort all the intervals based on the start time.
		// Sort with comparable.
		Collections.sort(intervals, new Comparator<Interval>() {
			@Override
			public int compare(Interval i1, Interval i2) {
				if (i1.start < i2.start)
					return -1;
				else if (i1.start == i2.start)
					return 0;
				else
					return 1;
			}
		});
		// Then for each interval [s1, e1], check if the next interval [s2, e2] can be merged or not.
		// 1) if e1 >= e2, merge the next interval, current interval unchanged.
		// 2) else if s2 <= e1 && e2 > e1, current interval = [s1, e2]
		// 3) else if s2 > e1, add current interval to result, move current interval to the next interval.
		Interval curr = new Interval(intervals.get(0).start, intervals.get(0).end);
		List<Interval> result = new ArrayList<Interval>();
		for (int i = 1; i < intervals.size(); i++) {
			Interval next = intervals.get(i);
			if (curr.end >= next.end) {
				// no need to do anything.
			} else if (curr.end >= next.start && curr.end < next.end) {
				curr.end = next.end;
			} else if (curr.end < next.start) {
				result.add(curr);
				curr = new Interval(next.start, next.end);
			}
		}
		result.add(curr);
		return result;
	}