1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-07 08:21:41 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2022-05-02 23:44:12 +08:00
parent 7ea03594b3
commit 2a71c78585
4790 changed files with 11696 additions and 10944 deletions

View File

@@ -12,7 +12,7 @@
"translatedContent": "<p>给你一个细长的画,用数轴表示。这幅画由若干有重叠的线段表示,每个线段有 <strong>独一无二</strong>&nbsp;的颜色。给你二维整数数组&nbsp;<code>segments</code>&nbsp;,其中&nbsp;<code>segments[i] = [start<sub>i</sub>, end<sub>i</sub>, color<sub>i</sub>]</code>&nbsp;表示线段为&nbsp;<strong>半开区间</strong>&nbsp;<code>[start<sub>i</sub>, end<sub>i</sub>)</code> 且颜色为&nbsp;<code>color<sub>i</sub></code>&nbsp;。</p>\n\n<p>线段间重叠部分的颜色会被 <strong>混合</strong>&nbsp;。如果有两种或者更多颜色混合时,它们会形成一种新的颜色,用一个 <strong>集合</strong>&nbsp;表示这个混合颜色。</p>\n\n<ul>\n\t<li>比方说,如果颜色&nbsp;<code>2</code>&nbsp;<code>4</code>&nbsp;和&nbsp;<code>6</code>&nbsp;被混合,那么结果颜色为&nbsp;<code>{2,4,6}</code>&nbsp;。</li>\n</ul>\n\n<p>为了简化题目,你不需要输出整个集合,只需要用集合中所有元素的 <strong>和</strong>&nbsp;来表示颜色集合。</p>\n\n<p>你想要用 <strong>最少数目</strong>&nbsp;不重叠 <strong>半开区间</strong>&nbsp;来 <b>表示</b>&nbsp;这幅混合颜色的画。这些线段可以用二维数组&nbsp;<code>painting</code>&nbsp;表示,其中 <code>painting[j] = [left<sub>j</sub>, right<sub>j</sub>, mix<sub>j</sub>]</code>&nbsp;表示一个&nbsp;<strong>半开区间</strong><code>[left<sub>j</sub>, right<sub>j</sub>)</code>&nbsp;的颜色 <strong>和</strong>&nbsp;为&nbsp;<code>mix<sub>j</sub></code>&nbsp;。</p>\n\n<ul>\n\t<li>比方说,这幅画由&nbsp;<code>segments = [[1,4,5],[1,7,7]]</code>&nbsp;组成,那么它可以表示为&nbsp;<code>painting = [[1,4,12],[4,7,7]]</code>&nbsp;,因为:\n\n\t<ul>\n\t\t<li><code>[1,4)</code>&nbsp;由颜色&nbsp;<code>{5,7}</code>&nbsp;组成(和为&nbsp;<code>12</code>),分别来自第一个线段和第二个线段。</li>\n\t\t<li><code>[4,7)</code>&nbsp;由颜色 <code>{7}</code>&nbsp;组成,来自第二个线段。</li>\n\t</ul>\n\t</li>\n</ul>\n\n<p>请你返回二维数组&nbsp;<code>painting</code>&nbsp;,它表示最终绘画的结果(<strong>没有</strong>&nbsp;被涂色的部分不出现在结果中)。你可以按 <strong>任意顺序</strong> 返回最终数组的结果。</p>\n\n<p><strong>半开区间&nbsp;</strong><code>[a, b)</code>&nbsp;是数轴上点&nbsp;<code>a</code> 和点&nbsp;<code>b</code>&nbsp;之间的部分,<strong>包含 </strong>点&nbsp;<code>a</code>&nbsp;且 <strong>不包含</strong>&nbsp;点&nbsp;<code>b</code>&nbsp;。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/18/1.png\" style=\"width: 529px; height: 241px;\">\n<pre><b>输入:</b>segments = [[1,4,5],[4,7,7],[1,7,9]]\n<b>输出:</b>[[1,4,14],[4,7,16]]\n<strong>解释:</strong>绘画借故偶可以表示为:\n- [1,4) 颜色为 {5,9} (和为 14分别来自第一和第二个线段。\n- [4,7) 颜色为 {7,9} (和为 16分别来自第二和第三个线段。\n</pre>\n\n<p><strong>示例 2</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/18/2.png\" style=\"width: 532px; height: 219px;\">\n<pre><b>输入:</b>segments = [[1,7,9],[6,8,15],[8,10,7]]\n<b>输出:</b>[[1,6,9],[6,7,24],[7,8,15],[8,10,7]]\n<b>解释:</b>绘画结果可以以表示为:\n- [1,6) 颜色为 9 ,来自第一个线段。\n- [6,7) 颜色为 {9,15} (和为 24来自第一和第二个线段。\n- [7,8) 颜色为 15 ,来自第二个线段。\n- [8,10) 颜色为 7 ,来自第三个线段。\n</pre>\n\n<p><strong>示例 3</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/07/04/c1.png\" style=\"width: 529px; height: 289px;\">\n<pre><b>输入:</b>segments = [[1,4,5],[1,4,7],[4,7,1],[4,7,11]]\n<b>输出:</b>[[1,4,12],[4,7,12]]\n<strong>解释:</strong>绘画结果可以表示为:\n- [1,4) 颜色为 {5,7} (和为 12分别来自第一和第二个线段。\n- [4,7) 颜色为 {1,11} (和为 12分别来自第三和第四个线段。\n注意只返回一个单独的线段 [1,7) 是不正确的,因为混合颜色的集合不相同。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= segments.length &lt;= 2 * 10<sup>4</sup></code></li>\n\t<li><code>segments[i].length == 3</code></li>\n\t<li><code>1 &lt;= start<sub>i</sub> &lt; end<sub>i</sub> &lt;= 10<sup>5</sup></code></li>\n\t<li><code>1 &lt;= color<sub>i</sub> &lt;= 10<sup>9</sup></code></li>\n\t<li>每种颜色&nbsp;<code>color<sub>i</sub></code>&nbsp;互不相同。</li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 14,
"likes": 15,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -131,7 +131,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"2.3K\", \"totalSubmission\": \"5.5K\", \"totalAcceptedRaw\": 2286, \"totalSubmissionRaw\": 5461, \"acRate\": \"41.9%\"}",
"stats": "{\"totalAccepted\": \"2.3K\", \"totalSubmission\": \"5.5K\", \"totalAcceptedRaw\": 2316, \"totalSubmissionRaw\": 5518, \"acRate\": \"42.0%\"}",
"hints": [
"Can we sort the segments in a way to help solve the problem?",
"How can we dynamically keep track of the sum of the current segment(s)?"