mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 12:16:14 -04:00
23 lines
493 B
Python
23 lines
493 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
# author: bt3gl
|
|
|
|
|
|
def non_overlapping_invervals(intervals):
|
|
|
|
if not intervals:
|
|
return 0
|
|
|
|
result = []
|
|
intervals.sort(key=lambda x: x[0])
|
|
heapq.heappush(result, intervals[0][-1])
|
|
|
|
for interval in intervals[1:]:
|
|
|
|
if result[0] <= interval[0]:
|
|
heapq.heappop(result)
|
|
|
|
heapq.heappush(result, interval[1])
|
|
|
|
return len(result)
|