Skip to content

Commit 48cf141

Browse files
committed
[20180411] medium problems
1 parent ea5ec89 commit 48cf141

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
| [0841](https://leetcode.com/problems/keys-and-rooms/) | Keys and Rooms | medium | [python](🤔medium/0841.Keys-and-Rooms/keys_and_rooms.py) | dfs, graph |
135135
| [0872](https://leetcode.com/problems/leaf-similar-trees/) | Leaf-Similar Trees | easy | python | |
136136
| [0876](https://leetcode.com/problems/middle-of-the-linked-list/) | Middle of the Linked List | easy | [python](🙂easy/0876.Middle-of-the-Linked-List/middle_of_the_linked_list.py) | |
137+
| [0890](https://leetcode.com/problems/find-and-replace-pattern/) | Find and Replace Pattern | medium | [python](🤔medium/0890.Find-and-Replace-Pattern/find_and_replace_pattern.py) | |
137138
| [0894](https://leetcode.com/problems/all-possible-full-binary-trees/) | All Possible Full Binary Trees | medium | [python](🤔medium/0894.All-Possible-Full-Binary-Trees/all_possible_full_binary_trees.py) | |
138139
| [0896](https://leetcode.com/problems/monotonic-array/) | Monotonic Array | easy | [python](🙂easy/0896.Monotonic-Array/monotonic_array.py) | |
139140
| [0905](https://leetcode.com/problems/sort-array-by-parity/) | Sort Array By Parity | easy | golang | |
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# 890. Find and Replace Pattern
2+
# https://leetcode.com/problems/find-and-replace-pattern/
3+
4+
from typing import List
5+
from collections import defaultdict
6+
7+
8+
class Solution:
9+
# pattern 에 맞는 word 를 찾아 리스트로 리턴하는 문제다.
10+
def findAndReplacePattern(self, words: List[str], pattern: str) -> List[str]:
11+
12+
# 딕셔너리 2개를 이용해서 1:1 매칭 되게 만들어주면 된다.
13+
res = []
14+
for word in words:
15+
d1 = defaultdict(str)
16+
d2 = defaultdict(str)
17+
for w, p in zip(word, pattern):
18+
if w not in d1:
19+
d1[w] = p
20+
if p not in d2:
21+
d2[p] = w
22+
23+
# 1:1 매칭이 안되면 종료
24+
if d1[w] != p or d2[p] != w:
25+
break
26+
else:
27+
res.append(word)
28+
29+
return res

0 commit comments

Comments
 (0)