Skip to content

Commit 5c1cf85

Browse files
Time: 52 ms (23.8%), Space: 73.7 MB (42.5%) - LeetHub
1 parent ae98d60 commit 5c1cf85

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public int eraseOverlapIntervals(int[][] intervals) {;
3+
Arrays.sort(intervals,(a,b)->a[1]-b[1]);
4+
Stack<int[]> stk = new Stack<>();
5+
int res=0;
6+
for(int[] i : intervals){
7+
if(!stk.isEmpty() && i[0]< stk.peek()[1]){
8+
res++;
9+
}else{
10+
stk.push(i);
11+
}
12+
}
13+
14+
return res;
15+
}
16+
}

0 commit comments

Comments
 (0)