Class Solution

java.lang.Object
g0301_0400.s0336_palindrome_pairs.Solution

public class Solution extends java.lang.Object
336 - Palindrome Pairs.

Hard

Given a list of unique words, return all the pairs of the distinct indices (i, j) in the given list, so that the concatenation of the two words words[i] + words[j] is a palindrome.

Example 1:

Input: words = [“abcd”,“dcba”,“lls”,“s”,“sssll”]

Output: [[0,1],[1,0],[3,2],[2,4]]

Explanation: The palindromes are [“dcbaabcd”,“abcddcba”,“slls”,“llssssll”]

Example 2:

Input: words = [“bat”,“tab”,“cat”]

Output: [[0,1],[1,0]]

Explanation: The palindromes are [“battab”,“tabbat”]

Example 3:

Input: words = [“a”,""]

Output: [[0,1],[1,0]]

Constraints:

  • 1 <= words.length <= 5000
  • 0 <= words[i].length <= 300
  • words[i] consists of lower-case English letters.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    java.util.List<java.util.List<java.lang.Integer>>
    palindromePairs(java.lang.String[] words)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • palindromePairs

      public java.util.List<java.util.List<java.lang.Integer>> palindromePairs(java.lang.String[] words)