mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-05 15:31:43 +08:00
存量题库数据更新
This commit is contained in:
@@ -1,15 +1,27 @@
|
||||
<p>Given a list of <b>unique</b> words, return all the pairs of the <b><i>distinct</i></b> indices <code>(i, j)</code> in the given list, so that the concatenation of the two words <code>words[i] + words[j]</code> is a palindrome.</p>
|
||||
<p>You are given a <strong>0-indexed</strong> array of <strong>unique</strong> strings <code>words</code>.</p>
|
||||
|
||||
<p>A <strong>palindrome pair</strong> is a pair of integers <code>(i, j)</code> such that:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= i, j < words.length</code>,</li>
|
||||
<li><code>i != j</code>, and</li>
|
||||
<li><code>words[i] + words[j]</code> (the concatenation of the two strings) is a <span data-keyword="palindrome-string">palindrome</span>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>an array of all the <strong>palindrome pairs</strong> of </em><code>words</code>.</p>
|
||||
|
||||
<p>You must write an algorithm with <code>O(sum of words[i].length)</code> runtime complexity.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> words = ["abcd","dcba","lls","s","sssll"]
|
||||
<strong>Output:</strong> [[0,1],[1,0],[3,2],[2,4]]
|
||||
<strong>Explanation:</strong> The palindromes are ["dcbaabcd","abcddcba","slls","llssssll"]
|
||||
<strong>Explanation:</strong> The palindromes are ["abcddcba","dcbaabcd","slls","llssssll"]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> words = ["bat","tab","cat"]
|
||||
@@ -17,11 +29,12 @@
|
||||
<strong>Explanation:</strong> The palindromes are ["battab","tabbat"]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> words = ["a",""]
|
||||
<strong>Output:</strong> [[0,1],[1,0]]
|
||||
<strong>Explanation:</strong> The palindromes are ["a","a"]
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
@@ -30,5 +43,5 @@
|
||||
<ul>
|
||||
<li><code>1 <= words.length <= 5000</code></li>
|
||||
<li><code>0 <= words[i].length <= 300</code></li>
|
||||
<li><code>words[i]</code> consists of lower-case English letters.</li>
|
||||
<li><code>words[i]</code> consists of lowercase English letters.</li>
|
||||
</ul>
|
||||
|
Reference in New Issue
Block a user