Skip to content

Commit f53161a

Browse files
refactor 435
1 parent 45d9170 commit f53161a

File tree

1 file changed

+3
-0
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+3
-0
lines changed

src/main/java/com/fishercoder/solutions/_435.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ public static class Solution1 {
1111
* and https://discuss.leetcode.com/topic/65594/java-least-is-most
1212
* Sort the intervals by their end time, if equal, then sort by their start time.
1313
* Then merge based on ending time.
14+
*
15+
* This comment is inspiring as of why sorting by end time could guarantee the correct answer: https://leetcode.com/problems/non-overlapping-intervals/discuss/91713/Java:-Least-is-Most/96271
16+
* In my words: if the earliest finished interval is not included, it's more likely that others (with later finish time) will overlap with others.
1417
*/
1518
public int eraseOverlapIntervals(int[][] intervals) {
1619
Arrays.sort(intervals, (a, b) -> a[1] != b[1] ? a[1] - b[1] : a[0] - b[0]);

0 commit comments

Comments
 (0)