We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3b0cd47 commit 51af125Copy full SHA for 51af125
1 file changed
non-overlapping-intervals/forest000014.java
@@ -0,0 +1,24 @@
1
+/*
2
+# Time Complexity: O(nlogn)
3
+ - 정렬 : O(nlogn)
4
+ - for-loop : O(n)
5
+# Space Complexity: O(1)
6
+*/
7
+class Solution {
8
+ public int eraseOverlapIntervals(int[][] intervals) {
9
+ Arrays.sort(intervals, (a, b) -> a[1] - b[1]);
10
+
11
+ int cnt = 0;
12
+ int prev_end = intervals[0][1];
13
14
+ for (int i = 1; i < intervals.length; i++) {
15
+ if (prev_end > intervals[i][0]) {
16
+ cnt++;
17
+ } else {
18
+ prev_end = intervals[i][1];
19
+ }
20
21
22
+ return cnt;
23
24
+}
0 commit comments