Skip to content

Commit

Permalink
1288
Browse files Browse the repository at this point in the history
  • Loading branch information
lzl124631x committed Feb 20, 2022
1 parent b494e3d commit 0a8b163
Showing 1 changed file with 12 additions and 26 deletions.
38 changes: 12 additions & 26 deletions leetcode/1288. Remove Covered Intervals/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# [1288. Remove Covered Intervals (Medium)](https://leetcode.com/problems/remove-covered-intervals/)

<p>Given a list of <code>intervals</code>, remove all intervals that are covered by another interval in the list.</p>
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p>

<p>Interval <code>[a,b)</code> is covered by&nbsp;interval <code>[c,d)</code> if and only if <code>c &lt;= a</code> and <code>b &lt;= d</code>.</p>
<p>The interval <code>[a, b)</code> is covered by the interval <code>[c, d)</code> if and only if <code>c &lt;= a</code> and <code>b &lt;= d</code>.</p>

<p>After doing so, return <em>the number of remaining intervals</em>.</p>
<p>Return <em>the number of remaining intervals</em>.</p>

<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>

<pre><strong>Input:</strong> intervals = [[1,4],[3,6],[2,8]]
<strong>Output:</strong> 2
<b>Explanation: </b>Interval [3,6] is covered by [2,8], therefore it is removed.
<strong>Explanation:</strong> Interval [3,6] is covered by [2,8], therefore it is removed.
</pre>

<p><strong>Example 2:</strong></p>
Expand All @@ -20,38 +20,24 @@
<strong>Output:</strong> 1
</pre>

<p><strong>Example 3:</strong></p>

<pre><strong>Input:</strong> intervals = [[0,10],[5,12]]
<strong>Output:</strong> 2
</pre>

<p><strong>Example 4:</strong></p>

<pre><strong>Input:</strong> intervals = [[3,10],[4,10],[5,11]]
<strong>Output:</strong> 2
</pre>

<p><strong>Example 5:</strong></p>

<pre><strong>Input:</strong> intervals = [[1,2],[1,4],[3,4]]
<strong>Output:</strong> 1
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>1 &lt;= intervals.length &lt;= 1000</code></li>
<li><code>intervals[i].length == 2</code></li>
<li><code>0 &lt;= intervals[i][0] &lt;&nbsp;intervals[i][1] &lt;= 10^5</code></li>
<li>All the intervals are <strong>unique</strong>.</li>
<li><code>0 &lt;= l<sub>i</sub> &lt;= r<sub>i</sub> &lt;= 10<sup>5</sup></code></li>
<li>All the given intervals are <strong>unique</strong>.</li>
</ul>


**Companies**:
[Facebook](https://leetcode.com/company/facebook), [Amazon](https://leetcode.com/company/amazon)

**Related Topics**:
[Greedy](https://leetcode.com/tag/greedy/), [Sort](https://leetcode.com/tag/sort/), [Line Sweep](https://leetcode.com/tag/line-sweep/)
[Array](https://leetcode.com/tag/array/), [Sorting](https://leetcode.com/tag/sorting/)

## Solution 1.
## Solution 1. Sorting + Greedy

```cpp
// OJ: https://leetcode.com/problems/remove-covered-intervals/
Expand Down

0 comments on commit 0a8b163

Please sign in to comment.