Class Solution

java.lang.Object
g0301_0400.s0336_palindrome_pairs.Solution

public class Solution extends Object
336 - Palindrome Pairs.<p>Hard</p> <p>Given a list of <strong>unique</strong> words, return all the pairs of the <strong><em>distinct</em></strong> 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><strong>Example 1:</strong></p> <p><strong>Input:</strong> words = [&ldquo;abcd&rdquo;,&ldquo;dcba&rdquo;,&ldquo;lls&rdquo;,&ldquo;s&rdquo;,&ldquo;sssll&rdquo;]</p> <p><strong>Output:</strong> [[0,1],[1,0],[3,2],[2,4]]</p> <p><strong>Explanation:</strong> The palindromes are [&ldquo;dcbaabcd&rdquo;,&ldquo;abcddcba&rdquo;,&ldquo;slls&rdquo;,&ldquo;llssssll&rdquo;]</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> words = [&ldquo;bat&rdquo;,&ldquo;tab&rdquo;,&ldquo;cat&rdquo;]</p> <p><strong>Output:</strong> [[0,1],[1,0]]</p> <p><strong>Explanation:</strong> The palindromes are [&ldquo;battab&rdquo;,&ldquo;tabbat&rdquo;]</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> words = [&ldquo;a&rdquo;,&quot;&quot;]</p> <p><strong>Output:</strong> [[0,1],[1,0]]</p> <p><strong>Constraints:</strong></p> <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> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details