mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-03 06:22:54 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>给你一个 <strong>互不相同</strong> 的整数数组,其中 <code>locations[i]</code> 表示第 <code>i</code> 个城市的位置。同时给你 <code>start</code>,<code>finish</code> 和 <code>fuel</code> 分别表示出发城市、目的地城市和你初始拥有的汽油总量</p>\n\n<p>每一步中,如果你在城市 <code>i</code> ,你可以选择任意一个城市 <code>j</code> ,满足 <code>j != i</code> 且 <code>0 <= j < locations.length</code> ,并移动到城市 <code>j</code> 。从城市 <code>i</code> 移动到 <code>j</code> 消耗的汽油量为 <code>|locations[i] - locations[j]|</code>,<code>|x|</code> 表示 <code>x</code> 的绝对值。</p>\n\n<p>请注意, <code>fuel</code> 任何时刻都 <strong>不能</strong> 为负,且你 <strong>可以</strong> 经过任意城市超过一次(包括 <code>start</code> 和 <code>finish</code> )。</p>\n\n<p>请你返回从<em> </em><code>start</code> 到 <code>finish</code> 所有可能路径的数目。</p>\n\n<p>由于答案可能很大, 请将它对 <code>10^9 + 7</code> 取余后返回。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>locations = [2,3,6,8,4], start = 1, finish = 3, fuel = 5\n<strong>输出:</strong>4\n<strong>解释:</strong>以下为所有可能路径,每一条都用了 5 单位的汽油:\n1 -> 3\n1 -> 2 -> 3\n1 -> 4 -> 3\n1 -> 4 -> 2 -> 3\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<strong>输入:</strong>locations = [4,3,1], start = 1, finish = 0, fuel = 6\n<strong>输出:</strong>5\n<strong>解释:</strong>以下为所有可能的路径:\n1 -> 0,使用汽油量为 fuel = 1\n1 -> 2 -> 0,使用汽油量为 fuel = 5\n1 -> 2 -> 1 -> 0,使用汽油量为 fuel = 5\n1 -> 0 -> 1 -> 0,使用汽油量为 fuel = 3\n1 -> 0 -> 1 -> 0 -> 1 -> 0,使用汽油量为 fuel = 5\n</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre>\n<strong>输入:</strong>locations = [5,2,1], start = 0, finish = 2, fuel = 3\n<strong>输出:</strong>0\n<strong>解释:</strong>没有办法只用 3 单位的汽油从 0 到达 2 。因为最短路径需要 4 单位的汽油。</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>2 <= locations.length <= 100</code></li>\n\t<li><code>1 <= locations[i] <= 10<sup>9</sup></code></li>\n\t<li>所有 <code>locations</code> 中的整数 <strong>互不相同</strong> 。</li>\n\t<li><code>0 <= start, finish < locations.length</code></li>\n\t<li><code>1 <= fuel <= 200</code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Hard",
|
||||
"likes": 60,
|
||||
"likes": 62,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -149,7 +149,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"6.3K\", \"totalSubmission\": \"10.6K\", \"totalAcceptedRaw\": 6307, \"totalSubmissionRaw\": 10579, \"acRate\": \"59.6%\"}",
|
||||
"stats": "{\"totalAccepted\": \"6.8K\", \"totalSubmission\": \"11.5K\", \"totalAcceptedRaw\": 6844, \"totalSubmissionRaw\": 11488, \"acRate\": \"59.6%\"}",
|
||||
"hints": [
|
||||
"Use dynamic programming to solve this problem with each state defined by the city index and fuel left.",
|
||||
"Since the array contains distinct integers fuel will always be spent in each move and so there can be no cycles."
|
||||
|
Reference in New Issue
Block a user