1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/插入区间 [insert-interval].html
2022-03-29 12:43:11 +08:00

54 lines
1.6 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><em> </em>按照区间起始端点排序的区间列表。</p>
<p>在列表中插入一个新的区间,你需要确保列表中的区间仍然有序且不重叠(如果有必要的话,可以合并区间)。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>intervals = [[1,3],[6,9]], newInterval = [2,5]
<strong>输出:</strong>[[1,5],[6,9]]
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]
<strong>输出:</strong>[[1,2],[3,10],[12,16]]
<strong>解释:</strong>这是因为新的区间 <code>[4,8]</code><code>[3,5],[6,7],[8,10]</code> 重叠。</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>intervals = [], newInterval = [5,7]
<strong>输出:</strong>[[5,7]]
</pre>
<p><strong>示例 4</strong></p>
<pre>
<strong>输入:</strong>intervals = [[1,5]], newInterval = [2,3]
<strong>输出:</strong>[[1,5]]
</pre>
<p><strong>示例 5</strong></p>
<pre>
<strong>输入:</strong>intervals = [[1,5]], newInterval = [2,7]
<strong>输出:</strong>[[1,7]]
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>0 <= intervals.length <= 10<sup>4</sup></code></li>
<li><code>intervals[i].length == 2</code></li>
<li><code>0 <= intervals[i][0] <= intervals[i][1] <= 10<sup>5</sup></code></li>
<li><code>intervals</code> 根据 <code>intervals[i][0]</code><strong>升序</strong> 排列</li>
<li><code>newInterval.length == 2</code></li>
<li><code>0 <= newInterval[0] <= newInterval[1] <= 10<sup>5</sup></code></li>
</ul>