mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-07 00:11:41 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>给你两个整数数组 <code>source</code> 和 <code>target</code> ,长度都是 <code>n</code> 。还有一个数组 <code>allowedSwaps</code> ,其中每个 <code>allowedSwaps[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> 表示你可以交换数组 <code>source</code> 中下标为 <code>a<sub>i</sub></code> 和 <code>b<sub>i</sub></code>(<strong>下标从 0 开始</strong>)的两个元素。注意,你可以按 <strong>任意</strong> 顺序 <strong>多次</strong> 交换一对特定下标指向的元素。</p>\n\n<p>相同长度的两个数组 <code>source</code> 和 <code>target</code> 间的 <strong>汉明距离</strong> 是元素不同的下标数量。形式上,其值等于满足 <code>source[i] != target[i]</code> (<strong>下标从 0 开始</strong>)的下标 <code>i</code>(<code>0 <= i <= n-1</code>)的数量。</p>\n\n<p>在对数组 <code>source</code> 执行 <strong>任意</strong> 数量的交换操作后,返回 <code>source</code> 和 <code>target</code> 间的 <strong>最小汉明距离</strong> 。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre><strong>输入:</strong>source = [1,2,3,4], target = [2,1,4,5], allowedSwaps = [[0,1],[2,3]]\n<strong>输出:</strong>1\n<strong>解释:</strong>source 可以按下述方式转换:\n- 交换下标 0 和 1 指向的元素:source = [<strong>2</strong>,<strong>1</strong>,3,4]\n- 交换下标 2 和 3 指向的元素:source = [2,1,<strong>4</strong>,<strong>3</strong>]\nsource 和 target 间的汉明距离是 1 ,二者有 1 处元素不同,在下标 3 。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre><strong>输入:</strong>source = [1,2,3,4], target = [1,3,2,4], allowedSwaps = []\n<strong>输出:</strong>2\n<strong>解释:</strong>不能对 source 执行交换操作。\nsource 和 target 间的汉明距离是 2 ,二者有 2 处元素不同,在下标 1 和下标 2 。</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre><strong>输入:</strong>source = [5,1,2,4,3], target = [1,5,4,2,3], allowedSwaps = [[0,4],[4,2],[1,3],[1,4]]\n<strong>输出:</strong>0\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>n == source.length == target.length</code></li>\n\t<li><code>1 <= n <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= source[i], target[i] <= 10<sup>5</sup></code></li>\n\t<li><code>0 <= allowedSwaps.length <= 10<sup>5</sup></code></li>\n\t<li><code>allowedSwaps[i].length == 2</code></li>\n\t<li><code>0 <= a<sub>i</sub>, b<sub>i</sub> <= n - 1</code></li>\n\t<li><code>a<sub>i</sub> != b<sub>i</sub></code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 52,
|
||||
"likes": 53,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -149,7 +149,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"5.2K\", \"totalSubmission\": \"10.2K\", \"totalAcceptedRaw\": 5214, \"totalSubmissionRaw\": 10210, \"acRate\": \"51.1%\"}",
|
||||
"stats": "{\"totalAccepted\": \"5.3K\", \"totalSubmission\": \"10.4K\", \"totalAcceptedRaw\": 5273, \"totalSubmissionRaw\": 10360, \"acRate\": \"50.9%\"}",
|
||||
"hints": [
|
||||
"The source array can be imagined as a graph where each index is a node and each allowedSwaps[i] is an edge.",
|
||||
"Nodes within the same component can be freely swapped with each other.",
|
||||
|
Reference in New Issue
Block a user