1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-22 13:36: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>有两个长度相同的字符串&nbsp;<code>s1</code> 和&nbsp;<code>s2</code>,且它们其中&nbsp;<strong>只含有</strong>&nbsp;字符&nbsp;<code>&quot;x&quot;</code> 和&nbsp;<code>&quot;y&quot;</code>,你需要通过「交换字符」的方式使这两个字符串相同。</p>\n\n<p>每次「交换字符」的时候,你都可以在两个字符串中各选一个字符进行交换。</p>\n\n<p>交换只能发生在两个不同的字符串之间,绝对不能发生在同一个字符串内部。也就是说,我们可以交换&nbsp;<code>s1[i]</code> 和&nbsp;<code>s2[j]</code>,但不能交换&nbsp;<code>s1[i]</code> 和&nbsp;<code>s1[j]</code>。</p>\n\n<p>最后,请你返回使 <code>s1</code> 和 <code>s2</code> 相同的最小交换次数,如果没有方法能够使得这两个字符串相同,则返回&nbsp;<code>-1</code> 。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre><strong>输入:</strong>s1 = &quot;xx&quot;, s2 = &quot;yy&quot;\n<strong>输出:</strong>1\n<strong>解释:\n</strong>交换 s1[0] 和 s2[1],得到 s1 = &quot;yx&quot;s2 = &quot;yx&quot;。</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre><strong>输入:</strong>s1 = &quot;xy&quot;, s2 = &quot;yx&quot;\n<strong>输出:</strong>2\n<strong>解释:\n</strong>交换 s1[0] 和 s2[0],得到 s1 = &quot;yy&quot;s2 = &quot;xx&quot; 。\n交换 s1[0] 和 s2[1],得到 s1 = &quot;xy&quot;s2 = &quot;xy&quot; 。\n注意你不能交换 s1[0] 和 s1[1] 使得 s1 变成 &quot;yx&quot;,因为我们只能交换属于两个不同字符串的字符。</pre>\n\n<p><strong>示例 3</strong></p>\n\n<pre><strong>输入:</strong>s1 = &quot;xx&quot;, s2 = &quot;xy&quot;\n<strong>输出:</strong>-1\n</pre>\n\n<p><strong>示例 4</strong></p>\n\n<pre><strong>输入:</strong>s1 = &quot;xxyyxyxyxx&quot;, s2 = &quot;xyyxyxxxyx&quot;\n<strong>输出:</strong>4\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= s1.length, s2.length &lt;= 1000</code></li>\n\t<li><code>s1, s2</code>&nbsp;只包含&nbsp;<code>&#39;x&#39;</code>&nbsp;或&nbsp;<code>&#39;y&#39;</code>。</li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 57,
"likes": 58,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -149,7 +149,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"10.4K\", \"totalSubmission\": \"16.6K\", \"totalAcceptedRaw\": 10359, \"totalSubmissionRaw\": 16579, \"acRate\": \"62.5%\"}",
"stats": "{\"totalAccepted\": \"10.7K\", \"totalSubmission\": \"17K\", \"totalAcceptedRaw\": 10657, \"totalSubmissionRaw\": 17044, \"acRate\": \"62.5%\"}",
"hints": [
"First, ignore all the already matched positions, they don't affect the answer at all. For the unmatched positions, there are three basic cases (already given in the examples):",
"(\"xx\", \"yy\") => 1 swap, (\"xy\", \"yx\") => 2 swaps",