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)/亲密字符串 [buddy-strings].html
2022-03-29 12:43:11 +08:00

41 lines
1.6 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>给你两个字符串 <code>s</code><code>goal</code> ,只要我们可以通过交换 <code>s</code> 中的两个字母得到与 <code>goal</code> 相等的结果,就返回&nbsp;<code>true</code>&nbsp;;否则返回 <code>false</code></p>
<p>交换字母的定义是:取两个下标 <code>i</code><code>j</code> (下标从 <code>0</code> 开始)且满足 <code>i != j</code> ,接着交换 <code>s[i]</code><code>s[j]</code> 处的字符。</p>
<ul>
<li>例如,在 <code>"abcd"</code> 中交换下标 <code>0</code> 和下标 <code>2</code> 的元素可以生成 <code>"cbad"</code></li>
</ul>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>s = "ab", goal = "ba"
<strong>输出:</strong>true
<strong>解释:</strong>你可以交换 s[0] = 'a' 和 s[1] = 'b' 生成 "ba",此时 s 和 goal 相等。</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>s = "ab", goal = "ab"
<strong>输出:</strong>false
<strong>解释:</strong>你只能交换 s[0] = 'a' 和 s[1] = 'b' 生成 "ba",此时 s 和 goal 不相等。</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>s = "aa", goal = "aa"
<strong>输出:</strong>true
<strong>解释:</strong>你可以交换 s[0] = 'a' 和 s[1] = 'a' 生成 "aa",此时 s 和 goal 相等。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length, goal.length &lt;= 2 * 10<sup>4</sup></code></li>
<li><code>s</code><code>goal</code> 由小写英文字母组成</li>
</ul>