Skip to content

Commit 6f8065e

Browse files
committed
solve 4
1 parent 5e8615b commit 6f8065e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

non-overlapping-intervals/pmjuu.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'''
2+
시간 복잡도: O(n log n)
3+
공간 복잡도: O(1)
4+
'''
5+
from typing import List
6+
7+
8+
class Solution:
9+
def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:
10+
intervals.sort()
11+
count = 0
12+
iter_intervals = iter(intervals)
13+
prev_end = next(iter_intervals)[1]
14+
15+
for start, end in iter_intervals:
16+
if prev_end > start:
17+
count += 1
18+
prev_end = min(prev_end, end)
19+
else:
20+
prev_end = end
21+
22+
return count

0 commit comments

Comments
 (0)