Skip to content

Commit 2615f35

Browse files
committed
feat: Solve non-overlapping-intervals problem
1 parent 3214067 commit 2615f35

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:
3+
intervals.sort()
4+
cnt = 0
5+
pre_end = intervals[0][1]
6+
for i in range(1, len(intervals)):
7+
start, end = intervals[i]
8+
if pre_end > start:
9+
cnt += 1
10+
pre_end = min(end, pre_end)
11+
else:
12+
pre_end = end
13+
return cnt

0 commit comments

Comments
 (0)