1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-27 18:50:26 +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 Normal View History

2023-12-09 18:42:21 +08:00
<p>给定一个由唯一字符串构成的 <strong>0 索引&nbsp;</strong>数组 <code>words</code>&nbsp;</p>
2022-03-27 20:56:26 +08:00
2023-12-09 18:42:21 +08:00
<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>
2022-03-27 20:56:26 +08:00
<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>
2023-12-09 18:42:21 +08:00
&nbsp;
2022-03-27 20:56:26 +08:00
<p><strong>提示:</strong></p>
<ul>
2023-12-09 18:42:21 +08:00
<li><code>1 &lt;= words.length &lt;= 5000</code></li>
<li><code>0 &lt;= words[i].length &lt;= 300</code></li>
2022-03-27 20:56:26 +08:00
<li><code>words[i]</code> 由小写英文字母组成</li>
</ul>