5634. 删除子字符串的最大得分
作者:
YueGuang
,
2021-01-10 00:26:49
,
所有人可见
,
阅读 348
class Solution:
def maximumGain(self, s: str, x: int, y: int) -> int:
res = 0
left, right = 0, 0
while right < len(s):
if s[right] != 'a' and s[right] != 'b':
string = s[left:right]
if x < y:
while 'ba' in string:
res += y
string = string.replace('ba', '', 1)
while 'ab' in string:
res += x
string = string.replace('ab', '', 1)
else:
while 'ab' in string:
res += x
string = string.replace('ab', '', 1)
while 'ba' in string:
res += y
string = string.replace('ba', '', 1)
left = right + 1
right += 1
string = s[left:right]
if x < y:
while 'ba' in string:
res += y
string = string.replace('ba', '', 1)
while 'ab' in string:
res += x
string = string.replace('ab', '', 1)
else:
while 'ab' in string:
res += x
string = string.replace('ab', '', 1)
while 'ba' in string:
res += y
string = string.replace('ba', '', 1)
return res
牛逼 真的能过