diff --git a/medium/word_subsets.py b/medium/word_subsets.py new file mode 100644 index 0000000..8331ea7 --- /dev/null +++ b/medium/word_subsets.py @@ -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