# 回文对

<p>给定一组<strong> 互不相同</strong> 的单词， 找出所有<strong> 不同<em> </em></strong>的索引对 <code>(i, j)</code>，使得列表中的两个单词， <code>words[i] + words[j]</code> ，可拼接成回文串。</p>

<p> </p>

<p><strong>示例 1：</strong></p>

<pre>
<strong>输入：</strong>words = ["abcd","dcba","lls","s","sssll"]
<strong>输出：</strong>[[0,1],[1,0],[3,2],[2,4]] 
<strong>解释：</strong>可拼接成的回文串为 <code>["dcbaabcd","abcddcba","slls","llssssll"]</code>
</pre>

<p><strong>示例 2：</strong></p>

<pre>
<strong>输入：</strong>words = ["bat","tab","cat"]
<strong>输出：</strong>[[0,1],[1,0]] 
<strong>解释：</strong>可拼接成的回文串为 <code>["battab","tabbat"]</code></pre>

<p><strong>示例 3：</strong></p>

<pre>
<strong>输入：</strong>words = ["a",""]
<strong>输出：</strong>[[0,1],[1,0]]
</pre>
 

<p><strong>提示：</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> 由小写英文字母组成</li>
</ul>


## template

```python
class Solution:
    def palindromePairs(self, words: List[str]) -> List[List[int]]:
        def is_palindrome(str, start, end):
            """检查子串是否是回文串
            """
            part_word = str[start : end + 1]
            return part_word == part_word[::-1]

        def find_reversed_word(str, start, end):
            """查找子串是否在哈希表中
            Return:
                不在哈希表中，返回 -1
                否则返回对应的索引
            """
            part_word = str[start : end + 1]
            ret = hash_map.get(part_word, -1)
            return ret

        hash_map = {}
        for i in range(len(words)):
            word = words[i][::-1]
            hash_map[word] = i

        res = []

        for i in range(len(words)):
            word = words[i]
            word_len = len(word)

            if is_palindrome(word, 0, word_len - 1) and "" in hash_map and word != "":
                res.append([hash_map.get(""), i])
            for j in range(word_len):

                if is_palindrome(word, j, word_len - 1):

                    left_part_index = find_reversed_word(word, 0, j - 1)

                    if left_part_index != -1 and left_part_index != i:
                        res.append([i, left_part_index])

                if is_palindrome(word, 0, j - 1):

                    right_part_index = find_reversed_word(word, j, word_len - 1)
                    if right_part_index != -1 and right_part_index != i:
                        res.append([right_part_index, i])

        return res

```

## 答案

```python

```

## 选项

### A

```python

```

### B

```python

```

### C

```python

```