码迷,mamicode.com
首页 > 其他好文 > 详细

[LeetCode] Palindrome Pairs 回文对

时间:2016-03-13 16:01:42      阅读:143      评论:0      收藏: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:
Given words = ["bat", "tab", "cat"]
Return [[0, 1], [1, 0]]
The palindromes are ["battab", "tabbat"]

Example 2:
Given words = ["abcd", "dcba", "lls", "s", "sssll"]
Return [[0, 1], [1, 0], [3, 2], [2, 4]]
The palindromes are ["dcbaabcd", "abcddcba", "slls", "llssssll"]

Credits:
Special thanks to @dietpepsi for adding this problem and creating all test cases.

 

[LeetCode] Palindrome Pairs 回文对

标签:

原文地址:http://www.cnblogs.com/grandyang/p/5272039.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!