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 ab27f8d commit 8a26cf0Copy full SHA for 8a26cf0
non-overlapping-intervals/HoonDongKang.ts
@@ -0,0 +1,25 @@
1
+/**
2
+ * [Problem]: [435] Non-overlapping Intervals
3
+ * (https://leetcode.com/problems/non-overlapping-intervals/description/)
4
+ */
5
+
6
+//시간복잡도 O(n log n)
7
+//공간복잡도 O(1)
8
+function eraseOverlapIntervals(intervals: number[][]): number {
9
+ intervals.sort((a, b) => a[1] - b[1]);
10
11
+ let count = 0;
12
+ let prev = intervals[0][1];
13
14
+ for (let i = 1; i < intervals.length; i++) {
15
+ let [start, end] = intervals[i];
16
17
+ if (prev > start) {
18
+ count++;
19
+ } else {
20
+ prev = end;
21
+ }
22
23
24
+ return count;
25
+}
0 commit comments