Skip to content

Commit 3394ebd

Browse files
authored
Update maximum-score-words-formed-by-letters.py
1 parent e12b97b commit 3394ebd

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Python/maximum-score-words-formed-by-letters.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ def maxScoreWords(self, words, letters, score):
1212
:type score: List[int]
1313
:rtype: int
1414
"""
15-
def backtracking(words, word_scores, word_counts, curr, curr_score, count, result):
15+
def backtracking(words, word_scores, word_counts, curr, curr_score, letter_count, result):
1616
result[0] = max(result[0], curr_score)
1717
for i in xrange(curr, len(words)):
18-
if any(count[c] < word_counts[i][c] for c in word_counts[i]):
18+
if any(letter_count[c] < word_counts[i][c] for c in word_counts[i]):
1919
continue
2020
backtracking(words, word_scores, word_counts, i+1,
21-
curr_score+word_scores[i], count-word_counts[i],
21+
curr_score+word_scores[i], letter_count-word_counts[i],
2222
result)
2323

2424
result = [0]
25-
count = collections.Counter(letters)
25+
letter_count = collections.Counter(letters)
2626
word_counts = map(collections.Counter, words)
2727
word_scores = [sum(score[ord(c)-ord('a')] for c in words[i])
2828
for i in xrange(len(words))]
29-
backtracking(words, word_scores, word_counts, 0, 0, count, result)
29+
backtracking(words, word_scores, word_counts, 0, 0, letter_count, result)
3030
return result[0]

0 commit comments

Comments
 (0)