This commit is contained in:
parent
c61b4932ce
commit
f5391da3ab
1 changed files with 18 additions and 0 deletions
18
easy/maximum_score_after_splitting_a_string.py
Normal file
18
easy/maximum_score_after_splitting_a_string.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# https://leetcode.com/problems/maximum-score-after-splitting-a-string
|
||||
|
||||
from collections import Counter
|
||||
|
||||
class Solution:
|
||||
def maxScore(self, s: str) -> int:
|
||||
counts = Counter(s)
|
||||
left_count = {}
|
||||
result = 0
|
||||
for i in range(len(s) - 1):
|
||||
counts[s[i]] -= 1
|
||||
if s[i] in left_count:
|
||||
left_count[s[i]] += 1
|
||||
else:
|
||||
left_count[s[i]] = 1
|
||||
result = max(result, left_count.get('0', 0) + counts.get('1', 0))
|
||||
return result
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue