We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 27e4c4c commit e579568Copy full SHA for e579568
non-overlapping-intervals/evan.py
@@ -0,0 +1,26 @@
1
+from typing import List
2
+
3
4
+class Solution:
5
+ def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:
6
+ if not intervals:
7
+ return 0
8
9
+ # Sort the intervals based on their end times
10
+ # to include as many meetings as possible
11
+ intervals.sort(key=lambda x: x[1])
12
13
+ # the count of non-overlapping intervals
14
+ count = 0
15
+ # the end time of the last added interval
16
+ end = float("-inf")
17
18
+ for interval in intervals:
19
+ if interval[0] >= end:
20
+ # If the current interval does not overlap with the last added interval, include it
21
+ end = interval[1]
22
+ else:
23
+ # Otherwise, increment the count of intervals to be removed
24
+ count += 1
25
26
+ return count
0 commit comments