# LeetCode: 916. 单词子集¶

## 1、题目描述¶

输入：A = ["amazon","apple","facebook","google","leetcode"], B = ["e","o"]



输入：A = ["amazon","apple","facebook","google","leetcode"], B = ["l","e"]



输入：A = ["amazon","apple","facebook","google","leetcode"], B = ["e","oo"]



输入：A = ["amazon","apple","facebook","google","leetcode"], B = ["lo","eo"]



输入：A = ["amazon","apple","facebook","google","leetcode"], B = ["ec","oc","ceo"]



• $1 <= A.length, B.length <= 10000$
• $1 <= A[i].length, B[i].length <= 10$
• A[i]B[i] 只由小写字母组成。
• A[i] 中所有的单词都是独一无二的，也就是说不存在 i != j 使得 A[i] == A[j]

## 2、解题思路¶

• 首先统计所有待判断的字符串中，字母出现的最大的频率，如果超过A中出现的频率，跳过当前单词，未超过，添加到结果集中
from collections import Counter, defaultdict

class Solution:
def wordSubsets(self, A: List[str], B: List[str]) -> List[str]:
ans = []
count_b = defaultdict(int)
for b in B:
for key, count in Counter(b).items():
count_b[key] = max(count_b[key], count)

for ai in A:
count_a = Counter(ai)
flag = True
for key, count in count_b.items():
if count> count_a[key]:
flag = False
break

if flag:
ans.append(ai)
return ans