java.lang.Object
g0401_0500.s0435_non_overlapping_intervals.Solution

public class Solution extends Object
435 - Non-overlapping Intervals.<p>Medium</p> <p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> intervals = [[1,2],[2,3],[3,4],[1,3]]</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> [1,3] can be removed and the rest of the intervals are non-overlapping.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> intervals = [[1,2],[1,2],[1,2]]</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> You need to remove two [1,2] to make the rest of the intervals non-overlapping.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> intervals = [[1,2],[2,3]]</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> You don&rsquo;t need to remove any of the intervals since they&rsquo;re already non-overlapping.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= intervals.length <= 10<sup>5</sup></code></li> <li><code>intervals[i].length == 2</code></li> <li><code>-5 * 10<sup>4</sup> <= start<sub>i</sub> < end<sub>i</sub> <= 5 * 10<sup>4</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • eraseOverlapIntervals

      public int eraseOverlapIntervals(int[][] intervals)