差不多硬幹
在下今天原本想學KMP的
但老天爺不給我機會
一輩子學不會KMP
def wordSubsets(self, words1: List[str], words2: List[str]) -> List[str]:
def check(a_cnt,b_cnt):
for i in range(26):
if b_cnt[i]>a_cnt[i]:
return False
return True
b_cnt = [0 for _ in range(26)]
for word in words2:
cnt_cur = [0 for _ in range(26)]
for c in word:
cnt_cur[ord(c)-ord('a')]+=1
for i in range(26):
b_cnt[i] = max(b_cnt[i], cnt_cur[i])
ans = []
for word in words1:
cnt_cur = [0 for _ in range(26)]
for c in word:
cnt_cur[ord(c)-ord('a')]+=1
if check(cnt_cur, b_cnt):
ans.append(word)
return ans