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 5ea3072 commit 8d2e6dcCopy full SHA for 8d2e6dc
non-overlapping-intervals/samthekorean.py
@@ -0,0 +1,16 @@
1
+# TC : O(n log n)
2
+# SC : O(n)
3
+class Solution:
4
+ def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:
5
+ res = 0
6
+
7
+ intervals.sort(key=lambda x: x[1])
8
+ prev_end = intervals[0][1]
9
10
+ for i in range(1, len(intervals)):
11
+ if prev_end > intervals[i][0]:
12
+ res += 1
13
+ else:
14
+ prev_end = intervals[i][1]
15
16
+ return res
0 commit comments