1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-25 06:48:57 +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>在一个无限的 x 坐标轴上,有许多水果分布在其中某些位置。给你一个二维整数数组 <code>fruits</code> ,其中 <code>fruits[i] = [position<sub>i</sub>, amount<sub>i</sub>]</code> 表示共有 <code>amount<sub>i</sub></code> 个水果放置在 <code>position<sub>i</sub></code> 上。<code>fruits</code> 已经按 <code>position<sub>i</sub></code> <strong>升序排列</strong> ,每个 <code>position<sub>i</sub></code> <strong>互不相同</strong> 。</p>\n\n<p>另给你两个整数 <code>startPos</code> 和 <code>k</code> 。最初,你位于 <code>startPos</code> 。从任何位置,你可以选择 <strong>向左或者向右</strong> 走。在 x 轴上每移动 <strong>一个单位</strong> ,就记作 <strong>一步</strong> 。你总共可以走 <strong>最多</strong> <code>k</code> 步。你每达到一个位置,都会摘掉全部的水果,水果也将从该位置消失(不会再生)。</p>\n\n<p>返回你可以摘到水果的 <strong>最大总数</strong> 。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/11/21/1.png\" style=\"width: 472px; height: 115px;\">\n<pre><strong>输入:</strong>fruits = [[2,8],[6,3],[8,6]], startPos = 5, k = 4\n<strong>输出:</strong>9\n<strong>解释:</strong>\n最佳路线为\n- 向右移动到位置 6 ,摘到 3 个水果\n- 向右移动到位置 8 ,摘到 6 个水果\n移动 3 步,共摘到 3 + 6 = 9 个水果\n</pre>\n\n<p><strong>示例 2</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/11/21/2.png\" style=\"width: 512px; height: 129px;\">\n<pre><strong>输入:</strong>fruits = [[0,9],[4,1],[5,7],[6,2],[7,4],[10,9]], startPos = 5, k = 4\n<strong>输出:</strong>14\n<strong>解释:</strong>\n可以移动最多 k = 4 步,所以无法到达位置 0 和位置 10 。\n最佳路线为\n- 在初始位置 5 ,摘到 7 个水果\n- 向左移动到位置 4 ,摘到 1 个水果\n- 向右移动到位置 6 ,摘到 2 个水果\n- 向右移动到位置 7 ,摘到 4 个水果\n移动 1 + 3 = 4 步,共摘到 7 + 1 + 2 + 4 = 14 个水果\n</pre>\n\n<p><strong>示例 3</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/11/21/3.png\" style=\"width: 476px; height: 100px;\">\n<pre><strong>输入:</strong>fruits = [[0,3],[6,4],[8,5]], startPos = 3, k = 2\n<strong>输出:</strong>0\n<strong>解释:</strong>\n最多可以移动 k = 2 步,无法到达任一有水果的地方\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= fruits.length &lt;= 10<sup>5</sup></code></li>\n\t<li><code>fruits[i].length == 2</code></li>\n\t<li><code>0 &lt;= startPos, position<sub>i</sub> &lt;= 2 * 10<sup>5</sup></code></li>\n\t<li>对于任意 <code>i &gt; 0</code> <code>position<sub>i-1</sub> &lt; position<sub>i</sub></code> 均成立(下标从 <strong>0</strong> 开始计数)</li>\n\t<li><code>1 &lt;= amount<sub>i</sub> &lt;= 10<sup>4</sup></code></li>\n\t<li><code>0 &lt;= k &lt;= 2 * 10<sup>5</sup></code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Hard",
"likes": 27,
"likes": 28,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -155,7 +155,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"3.7K\", \"totalSubmission\": \"11.2K\", \"totalAcceptedRaw\": 3670, \"totalSubmissionRaw\": 11199, \"acRate\": \"32.8%\"}",
"stats": "{\"totalAccepted\": \"3.8K\", \"totalSubmission\": \"11.6K\", \"totalAcceptedRaw\": 3795, \"totalSubmissionRaw\": 11550, \"acRate\": \"32.9%\"}",
"hints": [
"Does an optimal path have very few patterns? For example, could a path that goes left, turns and goes right, then turns again and goes left be any better than a path that simply goes left, turns, and goes right?",
"The optimal path turns at most once. That is, the optimal path is one of these: to go left only; to go right only; to go left, turn and go right; or to go right, turn and go left.",