blob: 7cde5e7927cfdd912f384d00cb904cc610ffc138 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# 1422. Maximum Score After Splitting a String
"""
given a string 's' of zeros and ones, return the maximum score after
splitting the string into two non-empty substrings (ie. left and right). the
score after splitting a string is the number of zeros in the left substring
plus the number of ones in the right substring.
"""
class Solution(object):
def maxScore(self, s):
"""
:type s: str
:rtype: int
"""
ans, zeros, ones = 0, 0, s.count("1")
for i in range(len(s) - 1):
if s[i] == "1":
ones -= 1
else:
zeros += 1
ans = max(ans, zeros + ones)
return ans
if __name__ == "__main__":
obj = Solution()
print(obj.maxScore("011101"))
print(obj.maxScore("00111"))
print(obj.maxScore("1111"))
|