From 1d01b3f104dc21ec259b4c5fe47e3b8d51b9f50d Mon Sep 17 00:00:00 2001 From: bumpsoo Date: Fri, 10 Jan 2025 21:21:47 +0900 Subject: [PATCH] https://leetcode.com/problems/word-subsets --- medium/word_subsets.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 medium/word_subsets.py 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