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)/特殊等价字符串组 [groups-of-special-equivalent-strings].html
2022-03-29 12:43:11 +08:00

53 lines
2.3 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>words</code></p>
<p>一步操作中,你可以交换字符串 <code>words[i]</code> 的任意两个偶数下标对应的字符或任意两个奇数下标对应的字符。</p>
<p>对两个字符串&nbsp;<code>words[i]</code><code>words[j]</code> 而言,如果经过任意次数的操作,<code>words[i] == words[j]</code> ,那么这两个字符串是 <strong>特殊等价 </strong>的。</p>
<ul>
<li>例如,<code>words[i] = "zzxy"</code><code>words[j] = "xyzz"</code> 是一对 <strong>特殊等价</strong> 字符串,因为可以按 <code>"zzxy" -&gt; "xzzy" -&gt; "xyzz"</code> 的操作路径使&nbsp;<code>words[i] == words[j]</code></li>
</ul>
<p>现在规定,<strong><code>words</code> </strong><strong>一组特殊等价字符串 </strong>就是 <code>words</code> 的一个同时满足下述条件的非空子集:</p>
<ul>
<li>该组中的每一对字符串都是<strong> 特殊等价 </strong></li>
<li>该组字符串已经涵盖了该类别中的所有特殊等价字符串,容量达到理论上的最大值(也就是说,如果一个字符串不在该组中,那么这个字符串就 <strong>不会</strong> 与该组内任何字符串特殊等价)</li>
</ul>
<p>返回 <code>words</code><strong>特殊等价字符串组</strong> 的数量。</p>
<p>&nbsp;</p>
<ul>
</ul>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>words = ["abcd","cdab","cbad","xyzz","zzxy","zzyx"]
<strong>输出:</strong>3
<strong>解释:</strong>
其中一组为 ["abcd", "cdab", "cbad"],因为它们是成对的特殊等价字符串,且没有其他字符串与这些字符串特殊等价。
另外两组分别是 ["xyzz", "zzxy"] 和 ["zzyx"]。特别需要注意的是,"zzxy" 不与 "zzyx" 特殊等价。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>words = ["abc","acb","bac","bca","cab","cba"]
<strong>输出:</strong>3
<strong>解释:</strong>3 组 ["abc","cba"]["acb","bca"]["bac","cab"]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= words.length &lt;= 1000</code></li>
<li><code>1 &lt;= words[i].length &lt;= 20</code></li>
<li>所有 <code>words[i]</code>&nbsp;都只由小写字母组成。</li>
<li>所有 <code>words[i]</code>&nbsp;都具有相同的长度。</li>
</ul>