1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-22 21:46:46 +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>0</strong> 开始的整数数组 <code>nums</code> ,该数组由 <strong>互不相同</strong> 的数字组成。另给你两个整数 <code>start</code> 和 <code>goal</code> 。</p>\n\n<p>整数 <code>x</code> 的值最开始设为 <code>start</code> ,你打算执行一些运算使 <code>x</code> 转化为 <code>goal</code> 。你可以对数字 <code>x</code> 重复执行下述运算:</p>\n\n<p>如果 <code>0 &lt;= x &lt;= 1000</code> ,那么,对于数组中的任一下标 <code>i</code><code>0 &lt;= i &lt; nums.length</code>),可以将 <code>x</code> 设为下述任一值:</p>\n\n<ul>\n\t<li><code>x + nums[i]</code></li>\n\t<li><code>x - nums[i]</code></li>\n\t<li><code>x ^ nums[i]</code>(按位异或 XOR</li>\n</ul>\n\n<p>注意,你可以按任意顺序使用每个 <code>nums[i]</code> 任意次。使 <code>x</code> 越过 <code>0 &lt;= x &lt;= 1000</code> 范围的运算同样可以生效,但该该运算执行后将不能执行其他运算。</p>\n\n<p>返回将 <code>x = start</code><em> </em>转化为<em> </em><code>goal</code><em> </em>的最小操作数;如果无法完成转化,则返回<em> </em><code>-1</code><em> </em>。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [2,4,12], start = 2, goal = 12\n<strong>输出:</strong>2\n<strong>解释:</strong>\n可以按 2 → 14 → 12 的转化路径进行,只需执行下述 2 次运算:\n- 2 + 12 = 14\n- 14 - 2 = 12\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [3,5,7], start = 0, goal = -4\n<strong>输出:</strong>2\n<strong>解释:</strong>\n可以按 0 → 3 → -4 的转化路径进行,只需执行下述 2 次运算:\n- 0 + 3 = 3\n- 3 - 7 = -4\n注意最后一步运算使 x 超过范围 0 &lt;= x &lt;= 1000 ,但该运算仍然可以生效。\n</pre>\n\n<p><strong>示例 3</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [2,8,16], start = 0, goal = 1\n<strong>输出:</strong>-1\n<strong>解释:</strong>\n无法将 0 转化为 1</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= nums.length &lt;= 1000</code></li>\n\t<li><code>-10<sup>9</sup> &lt;= nums[i], goal &lt;= 10<sup>9</sup></code></li>\n\t<li><code>0 &lt;= start &lt;= 1000</code></li>\n\t<li><code>start != goal</code></li>\n\t<li><code>nums</code> 中的所有整数互不相同</li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 27,
"likes": 29,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -143,7 +143,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"4.6K\", \"totalSubmission\": \"10.5K\", \"totalAcceptedRaw\": 4623, \"totalSubmissionRaw\": 10485, \"acRate\": \"44.1%\"}",
"stats": "{\"totalAccepted\": \"4.8K\", \"totalSubmission\": \"10.8K\", \"totalAcceptedRaw\": 4800, \"totalSubmissionRaw\": 10831, \"acRate\": \"44.3%\"}",
"hints": [
"Once x drops below 0 or goes above 1000, is it possible to continue performing operations on x?",
"How can you use BFS to find the minimum operations?"