From f5391da3ab8f3518cfbe83bc1e2cca8d03e7426d Mon Sep 17 00:00:00 2001 From: bumpsoo Date: Wed, 1 Jan 2025 15:08:51 +0900 Subject: [PATCH] https://leetcode.com/problems/maximum-score-after-splitting-a-string --- easy/maximum_score_after_splitting_a_string.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 easy/maximum_score_after_splitting_a_string.py diff --git a/easy/maximum_score_after_splitting_a_string.py b/easy/maximum_score_after_splitting_a_string.py new file mode 100644 index 0000000..fe83706 --- /dev/null +++ b/easy/maximum_score_after_splitting_a_string.py @@ -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 +