This commit is contained in:
parent
149a0df863
commit
1d01b3f104
1 changed files with 17 additions and 0 deletions
17
medium/word_subsets.py
Normal file
17
medium/word_subsets.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# https://leetcode.com/problems/word-subsets
|
||||
|
||||
from typing import Counter, Dict, List
|
||||
|
||||
class Solution:
|
||||
def wordSubsets(self, words1: List[str], words2: List[str]) -> List[str]:
|
||||
result = []
|
||||
count: Dict[str, int] = {}
|
||||
for word2 in words2:
|
||||
c = Counter(word2)
|
||||
for k, v in c.items():
|
||||
count[k] = max(count.setdefault(k, 0), v)
|
||||
for word1 in words1:
|
||||
c = Counter(word1)
|
||||
if all(c.get(k, 0) >= v for k, v in count.items()):
|
||||
result.append(word1)
|
||||
return result
|
||||
Loading…
Add table
Add a link
Reference in a new issue