美文网首页
Palindrome Pairs

Palindrome Pairs

作者: aemaeth | 来源:发表于2016-03-13 00:08 被阅读0次

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

  • Example 1:Givenwords
    =["bat", "tab", "cat"]
    Return[[0, 1], [1, 0]]
    The palindromes are["battab", "tabbat"]
  • Example 2:Givenwords
    =["abcd", "dcba", "lls", "s", "sssll"]
    Return[[0, 1], [1, 0], [3, 2], [2, 4]]
    The palindromes are["dcbaabcd", "abcddcba", "slls", "llssssll"]

相关文章

网友评论

      本文标题:Palindrome Pairs

      本文链接:https://www.haomeiwen.com/subject/qxexlttx.html