bumpsoo 2025-01-10 21:21:47 +09:00
parent 149a0df863
commit 1d01b3f104

17
medium/word_subsets.py Normal file
View 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