File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
non-overlapping-intervals Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * <a href="https://leetcode.com/problems/non-overlapping-intervals/">week12-3. non-overlapping-intervals</a>
3
+ * <li>Description: return the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</li>
4
+ * <li>Topics: Array, Dynamic Programming, Greedy, Sorting </li>
5
+ * <li>Time Complexity: O(N), Runtime 45ms </li>
6
+ * <li>Space Complexity: O(1), Memory 73.45MB </li>
7
+ * <li>Note : refer to the answer </li>
8
+ */
9
+ class Solution {
10
+ public int eraseOverlapIntervals (int [][] intervals ) {
11
+ Arrays .sort (intervals , (i1 , i2 ) -> i1 [1 ] - i2 [1 ]);
12
+
13
+ int skip = 0 ;
14
+ int end = Integer .MIN_VALUE ;
15
+
16
+ for (int [] interval : intervals ) {
17
+ if (interval [0 ] < end ) {
18
+ skip ++;
19
+ } else {
20
+ end = interval [1 ];
21
+ }
22
+ }
23
+
24
+ return skip ;
25
+ }
26
+ }
You can’t perform that action at this time.
0 commit comments