1 class Solution: 2 def maxScore(self, s: str) -> int: 3 ans,lens = 0,len(s) 4 cnt0 = s.count('0') 5 cnt1 = lens - cnt0 6 cur0 = cur1 = 0 7 for i in range(lens - 1): 8 cur0 += int(s[i] == '0') 9 cur1 += int(s[i] == '1') 10 ans = max(ans,cur0 + cnt1 - cur1) 11 return ans