1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/使字符串总不同字符的数目相等 [make-number-of-distinct-characters-equal].html
2023-01-14 00:20:24 +08:00

42 lines
1.7 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你两个下标从 <strong>0</strong> 开始的字符串 <code>word1</code><code>word2</code></p>
<p>一次 <strong>移动</strong> 由以下两个步骤组成:</p>
<ul>
<li>选中两个下标&nbsp;<code>i</code><code>j</code> ,分别满足 <code>0 &lt;= i &lt; word1.length</code><code>0 &lt;= j &lt; word2.length</code> </li>
<li>交换 <code>word1[i]</code><code>word2[j]</code></li>
</ul>
<p>如果可以通过 <strong>恰好一次</strong> 移动,使 <code>word1</code><code>word2</code> 中不同字符的数目相等,则返回 <code>true</code> ;否则,返回 <code>false</code></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>word1 = "ac", word2 = "b"
<strong>输出:</strong>false
<strong>解释:</strong>交换任何一组下标都会导致第一个字符串中有 2 个不同的字符,而在第二个字符串中只有 1 个不同字符。
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>word1 = "abcc", word2 = "aab"
<strong>输出:</strong>true
<strong>解释:</strong>交换第一个字符串的下标 2 和第二个字符串的下标 0 。之后得到 word1 = "abac" 和 word2 = "cab" ,各有 3 个不同字符。
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>word1 = "abcde", word2 = "fghij"
<strong>输出:</strong>true
<strong>解释:</strong>无论交换哪一组下标,两个字符串中都会有 5 个不同字符。</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= word1.length, word2.length &lt;= 10<sup>5</sup></code></li>
<li><code>word1</code><code>word2</code> 仅由小写英文字母组成。</li>
</ul>