Skip to content

Commit 77437e8

Browse files
committed
Added Non-overlapping Intervals.java
1 parent 86f10a6 commit 77437e8

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

Medium/Non Overlapping Intervals.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

Medium/Non-overlapping Intervals.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public int eraseOverlapIntervals(int[][] intervals) {
3+
Arrays.sort(intervals, Comparator.comparingInt((int[] o) -> o[1]));
4+
int result = 0;
5+
int minEndTime = Integer.MIN_VALUE;
6+
for (int i = 0; i < intervals.length; i++) {
7+
int start = intervals[i][0];
8+
int end = intervals[i][1];
9+
if (start >= minEndTime) {
10+
minEndTime = end;
11+
} else {
12+
result++;
13+
}
14+
}
15+
return result;
16+
}
17+
}

0 commit comments

Comments
 (0)