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)/判断通过操作能否让字符串相等 II [check-if-strings-can-be-made-equal-with-operations-ii].html
2023-09-09 15:37:57 +08:00

45 lines
1.7 KiB
HTML
Raw Permalink 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>给你两个字符串&nbsp;<code>s1</code>&nbsp;&nbsp;<code>s2</code>&nbsp;,两个字符串长度都为&nbsp;<code>n</code>&nbsp;,且只包含&nbsp;<strong>小写&nbsp;</strong>英文字母。</p>
<p>你可以对两个字符串中的 <strong>任意一个</strong>&nbsp;执行以下操作 <strong>任意</strong>&nbsp;次:</p>
<ul>
<li>选择两个下标&nbsp;<code>i</code>&nbsp;<code>j</code>&nbsp;,满足 <code>i &lt; j</code>&nbsp;<code>j - i</code>&nbsp;<strong>偶数</strong>,然后 <strong>交换</strong> 这个字符串中两个下标对应的字符。</li>
</ul>
<p>&nbsp;</p>
<p>如果你可以让字符串<em>&nbsp;</em><code>s1</code><em> </em><em>&nbsp;</em><code>s2</code>&nbsp;相等,那么返回 <code>true</code>&nbsp;,否则返回 <code>false</code>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<b>输入:</b>s1 = "abcdba", s2 = "cabdab"
<b>输出:</b>true
<b>解释:</b>我们可以对 s1 执行以下操作:
- 选择下标 i = 0 j = 2 ,得到字符串 s1 = "cbadba" 。
- 选择下标 i = 2 j = 4 ,得到字符串 s1 = "cbbdaa" 。
- 选择下标 i = 1 j = 5 ,得到字符串 s1 = "cabdab" = s2 。
</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<b>输入:</b>s1 = "abe", s2 = "bea"
<b>输出:</b>false
<b>解释:</b>无法让两个字符串相等。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == s1.length == s2.length</code></li>
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>s1</code>&nbsp;<code>s2</code>&nbsp;只包含小写英文字母。</li>
</ul>