File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -27,9 +27,9 @@ public List<Interval> merge(List<Interval> intervals) {
27
27
if (intervals == null || intervals .size () == 0 ) return res ;
28
28
Collections .sort (intervals , new MyComparator ());
29
29
for (Interval i : intervals ) {
30
- if (res .isEmpty ()) res .add (i );
30
+ if (res .isEmpty ()) res .add (i ); // first interval
31
31
else {
32
- Interval last = res .get (res .size () - 1 );
32
+ Interval last = res .get (res .size () - 1 ); // get last interval
33
33
if (last .end >= i .start ) { // overlap
34
34
res .remove (last );
35
35
res .add (new Interval (last .start , Math .max (last .end , i .end ))); // extend end
@@ -39,6 +39,10 @@ public List<Interval> merge(List<Interval> intervals) {
39
39
return res ;
40
40
}
41
41
42
+ /**
43
+ * Comparator for interval
44
+ * Sort according to start date
45
+ */
42
46
class MyComparator implements Comparator <Interval > {
43
47
44
48
@ Override
You can’t perform that action at this time.
0 commit comments