Re: [閒聊] 每日leetcode

作者: DJYOSHITAKA (Evans)   2024-05-24 23:20:26
比昨天的簡單
昨天的好難
我好爛==
def maxScoreWords(self, words: List[str], letters: List[str], score:
List[int]) -> int:
ans = 0
letters_cnt = [letters.count(chr(i)) for i in range(ord('a'), ord('z')+1)]
n = len(words)
def dfs(idx, score_cur):
nonlocal ans
if idx == n:
ans = max(score_cur, ans)
return
if all([ words[idx].count(c) <= letters_cnt[ord(c)-ord('a')] for c in
words[idx] ]):
score_add = sum([score[ord(c) - ord('a')] for c in words[idx]])
score_cur += score_add
for c in words[idx]:
letters_cnt[ord(c) - ord('a')] -= 1
dfs(idx+1, score_cur)
score_cur -= score_add
for c in words[idx]:
letters_cnt[ord(c) - ord('a')] += 1
dfs(idx+1, score_cur)
dfs(0, 0)
return ans
作者: sustainer123 (caster)   2024-05-24 23:21:00
我也感覺這題沒比昨天難多少
作者: JIWP (JIWP)   2024-05-24 23:24:00
剩我不會寫hard了
作者: sustainer123 (caster)   2024-05-24 23:25:00
你是兩百天大師

Links booklink

Contact Us: admin [ a t ] ucptt.com