1537. Maximum Score After Splitting a String
My accepted Python solution to LeetCode problem 1537, Maximum Score After Splitting a String, running in 4ms.
- Difficulty: Easy
- Python
- Runtime 4ms
- Memory 17.2MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 4ms, memory 17.2MB, accepted 2025-12-29.
class Solution:
def maxScore(self, s: str) -> int:
max_score = 0
zeros = 0
ones = s.count('1')
for i in range(len(s) - 1):
if s[i] == '0':
zeros += 1
else:
ones -= 1
max_score = max(max_score, zeros + ones)
return max_score