mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-22 13:36:46 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>有两个长度相同的字符串 <code>s1</code> 和 <code>s2</code>,且它们其中 <strong>只含有</strong> 字符 <code>"x"</code> 和 <code>"y"</code>,你需要通过「交换字符」的方式使这两个字符串相同。</p>\n\n<p>每次「交换字符」的时候,你都可以在两个字符串中各选一个字符进行交换。</p>\n\n<p>交换只能发生在两个不同的字符串之间,绝对不能发生在同一个字符串内部。也就是说,我们可以交换 <code>s1[i]</code> 和 <code>s2[j]</code>,但不能交换 <code>s1[i]</code> 和 <code>s1[j]</code>。</p>\n\n<p>最后,请你返回使 <code>s1</code> 和 <code>s2</code> 相同的最小交换次数,如果没有方法能够使得这两个字符串相同,则返回 <code>-1</code> 。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre><strong>输入:</strong>s1 = "xx", s2 = "yy"\n<strong>输出:</strong>1\n<strong>解释:\n</strong>交换 s1[0] 和 s2[1],得到 s1 = "yx",s2 = "yx"。</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre><strong>输入:</strong>s1 = "xy", s2 = "yx"\n<strong>输出:</strong>2\n<strong>解释:\n</strong>交换 s1[0] 和 s2[0],得到 s1 = "yy",s2 = "xx" 。\n交换 s1[0] 和 s2[1],得到 s1 = "xy",s2 = "xy" 。\n注意,你不能交换 s1[0] 和 s1[1] 使得 s1 变成 "yx",因为我们只能交换属于两个不同字符串的字符。</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre><strong>输入:</strong>s1 = "xx", s2 = "xy"\n<strong>输出:</strong>-1\n</pre>\n\n<p><strong>示例 4:</strong></p>\n\n<pre><strong>输入:</strong>s1 = "xxyyxyxyxx", s2 = "xyyxyxxxyx"\n<strong>输出:</strong>4\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= s1.length, s2.length <= 1000</code></li>\n\t<li><code>s1, s2</code> 只包含 <code>'x'</code> 或 <code>'y'</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",
|
||||
|
Reference in New Issue
Block a user