1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/区间列表的交集 [interval-list-intersections].html
2022-03-29 12:43:11 +08:00

51 lines
2.1 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给定两个由一些<strong> 闭区间 </strong>组成的列表,<code>firstList</code><code>secondList</code> ,其中 <code>firstList[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> 而 <code>secondList[j] = [start<sub>j</sub>, end<sub>j</sub>]</code> 。每个区间列表都是成对 <strong>不相交</strong> 的,并且 <strong>已经排序</strong></p>
<p>返回这 <strong>两个区间列表的交集</strong></p>
<p>形式上,<strong>闭区间</strong> <code>[a, b]</code>(其中 <code>a <= b</code>)表示实数 <code>x</code> 的集合,而 <code>a <= x <= b</code></p>
<p>两个闭区间的 <strong>交集</strong> 是一组实数,要么为空集,要么为闭区间。例如,<code>[1, 3]</code><code>[2, 4]</code> 的交集为 <code>[2, 3]</code></p>
<p> </p>
<p><strong>示例 1</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2019/01/30/interval1.png" style="width: 700px; height: 194px;" />
<pre>
<strong>输入:</strong>firstList = [[0,2],[5,10],[13,23],[24,25]], secondList = [[1,5],[8,12],[15,24],[25,26]]
<strong>输出:</strong>[[1,2],[5,5],[8,10],[15,23],[24,24],[25,25]]
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>firstList = [[1,3],[5,9]], secondList = []
<strong>输出:</strong>[]
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>firstList = [], secondList = [[4,8],[10,12]]
<strong>输出:</strong>[]
</pre>
<p><strong>示例 4</strong></p>
<pre>
<strong>输入:</strong>firstList = [[1,7]], secondList = [[3,10]]
<strong>输出:</strong>[[3,7]]
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>0 <= firstList.length, secondList.length <= 1000</code></li>
<li><code>firstList.length + secondList.length >= 1</code></li>
<li><code>0 <= start<sub>i</sub> < end<sub>i</sub> <= 10<sup>9</sup></code></li>
<li><code>end<sub>i</sub> < start<sub>i+1</sub></code></li>
<li><code>0 <= start<sub>j</sub> < end<sub>j</sub> <= 10<sup>9</sup> </code></li>
<li><code>end<sub>j</sub> < start<sub>j+1</sub></code></li>
</ul>