1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/判断通过操作能否让字符串相等 I [check-if-strings-can-be-made-equal-with-operations-i].html

39 lines
1.5 KiB
HTML
Raw Normal View History

2023-09-09 15:37:57 +08:00
<p>给你两个字符串&nbsp;<code>s1</code>&nbsp;<code>s2</code>&nbsp;,两个字符串的长度都为&nbsp;<code>4</code>&nbsp;,且只包含 <strong>小写</strong> 英文字母。</p>
<p>你可以对两个字符串中的 <strong>任意一个</strong>&nbsp;执行以下操作 <strong>任意</strong>&nbsp;次:</p>
<ul>
<li>选择两个下标&nbsp;<code>i</code>&nbsp;<code>j</code>&nbsp;且满足&nbsp;<code>j - i = 2</code>&nbsp;,然后 <strong>交换</strong> 这个字符串中两个下标对应的字符。</li>
</ul>
<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><strong class="example">示例 1</strong></p>
<pre>
<b>输入:</b>s1 = "abcd", s2 = "cdab"
<b>输出:</b>true
<strong>解释:</strong> 我们可以对 s1 执行以下操作:
- 选择下标 i = 0 j = 2 ,得到字符串 s1 = "cbad" 。
- 选择下标 i = 1 j = 3 ,得到字符串 s1 = "cdab" = s2 。
</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<b>输入:</b>s1 = "abcd", s2 = "dacb"
<b>输出:</b>false
<b>解释:</b>无法让两个字符串相等。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>s1.length == s2.length == 4</code></li>
<li><code>s1</code>&nbsp;<code>s2</code>&nbsp;只包含小写英文字母。</li>
</ul>