We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2edcffe commit b5240c9Copy full SHA for b5240c9
Palindrome Pairs/Solution.py
@@ -0,0 +1,18 @@
1
+class Solution:
2
+ def palindromePairs(self, words: List[str]) -> List[List[int]]:
3
+ ans = []
4
+ dict = {word[::-1]: i for i, word in enumerate(words)}
5
+
6
+ for i, word in enumerate(words):
7
+ if "" in dict and dict[""] != i and word == word[::-1]:
8
+ ans.append([i, dict[""]])
9
10
+ for j in range(1, len(word) + 1):
11
+ l = word[:j]
12
+ r = word[j:]
13
+ if l in dict and dict[l] != i and r == r[::-1]:
14
+ ans.append([i, dict[l]])
15
+ if r in dict and dict[r] != i and l == l[::-1]:
16
+ ans.append([dict[r], i])
17
18
+ return ans
0 commit comments