Re: [閒聊] 每日leetcode

作者: DJYOMIYAHINA (通通打死)   2025-01-10 21:48:12
差不多硬幹
在下今天原本想學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
作者: Firstshadow (IamCatづミ'_'ミづ)   2024-01-10 21:48:00
你板剩窩不會寫代碼了==
作者: oin1104 (是oin的說)   2024-01-10 21:48:00
kmp = 背模板就好
作者: Firstshadow (IamCatづミ'_'ミづ)   2025-01-10 21:49:00
連模板都背不起來 嗚嗚哇哇哇
作者: pandix (麵包屌)   2025-01-10 21:50:00
kmp=糞肏:o
作者: sustainer123 (caster)   2025-01-10 21:52:00
kmp 真的好難
作者: Furina (芙寧娜)   2025-01-10 22:13:00
大師

Links booklink

Contact Us: admin [ a t ] ucptt.com