bumpsoo 2025-01-01 15:08:51 +09:00
parent c61b4932ce
commit f5391da3ab

View 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