题目
Given a collection of intervals, find the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.
Example 1:
1 | Input: [[1,2],[2,3],[3,4],[1,3]] |
Example 2:
1 | Input: [[1,2],[1,2],[1,2]] |
Example 3:
1 | Input: [[1,2],[2,3]] |
Note:
- You may assume the interval’s end point is always bigger than its start point.
- Intervals like [1,2] and [2,3] have borders “touching” but they don’t overlap each other.
思路
Sort + Greedy.
代码
1 | class Solution(object): |