Skip to content

Files

Latest commit

author
Shuo
Feb 16, 2022
ce6b544 · Feb 16, 2022

History

History

palindrome-pairs

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Feb 16, 2022
Nov 12, 2019
Nov 12, 2019

README.md

< Previous                  Next >

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.

Related Topics

[Array] [Hash Table] [String] [Trie]

Similar Questions

  1. Longest Palindromic Substring (Medium)
  2. Shortest Palindrome (Hard)
  3. Longest Palindrome by Concatenating Two Letter Words (Medium)