We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1c8e8d6 commit 604fbceCopy full SHA for 604fbce
HT/890.md
@@ -0,0 +1,42 @@
1
+## Find and Replace Pattern
2
+
3
+#### Description
4
5
+[link](https://leetcode.com/problems/find-and-replace-pattern/)
6
7
+---
8
9
+#### Solution
10
11
+- See Code
12
13
14
15
+#### Code
16
17
+> Complexity T : O(n) M : O(n)
18
19
+```python
20
+class Solution:
21
+ def findAndReplacePattern(self, words: List[str], pattern: str) -> List[str]:
22
+ res = []
23
24
+ def match(word, pattern):
25
+ if len(word) != len(pattern):
26
+ return False
27
+ d = {}
28
+ for w, p in zip(word, pattern):
29
+ if w not in d:
30
+ if p in d.values():
31
32
+ d[w] = p
33
+ else:
34
+ if d[w] != p:
35
36
+ return True
37
38
+ for w in words:
39
+ if match(w, pattern):
40
+ res.append(w)
41
+ return res
42
+```
0 commit comments