1653. Minimum Deletions to Make String Balanced

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 1653

class Solution:
    def minimumDeletions(self, s: str) -> int:
        lb, ra = 0, s.count('a')
        res = len(s)
        for c in s:
            ra -= c == 'a'
            res = min(res, lb + ra)
            lb += c == 'b'
        return res