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)/回文对 [palindrome-pairs].html

47 lines
1.5 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 索引&nbsp;</strong>数组 <code>words</code>&nbsp;</p>
<p><strong>回文对</strong> 是一对整数 <code>(i, j)</code> ,满足以下条件:</p>
<ul>
<li><code>0 &lt;= i, j &lt; words.length</code></li>
<li><code>i != j</code> ,并且</li>
<li><code>words[i] + words[j]</code>(两个字符串的连接)是一个回文。</li>
</ul>
<p>返回一个数组,它包含&nbsp;<code>words</code> 中所有满足 <strong>回文对</strong> 条件的字符串。</p>
<p>你必须设计一个时间复杂度为 <code>O(sum of words[i].length)</code> 的算法。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>words = ["abcd","dcba","lls","s","sssll"]
<strong>输出:</strong>[[0,1],[1,0],[3,2],[2,4]]
<strong>解释:</strong>可拼接成的回文串为 <code>["dcbaabcd","abcddcba","slls","llssssll"]</code>
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>words = ["bat","tab","cat"]
<strong>输出:</strong>[[0,1],[1,0]]
<strong>解释:</strong>可拼接成的回文串为 <code>["battab","tabbat"]</code></pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>words = ["a",""]
<strong>输出:</strong>[[0,1],[1,0]]
</pre>
&nbsp;
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= words.length &lt;= 5000</code></li>
<li><code>0 &lt;= words[i].length &lt;= 300</code></li>
<li><code>words[i]</code> 由小写英文字母组成</li>
</ul>