Skip to content

Latest commit

 

History

History
22 lines (20 loc) · 477 Bytes

1653.md

File metadata and controls

22 lines (20 loc) · 477 Bytes

1653. Minimum Deletions to Make String Balanced

Solution 1 (time O(n), space O(1))

class Solution(object):
    def minimumDeletions(self, s):
        """
        :type s: str
        :rtype: int
        """
        leftb = 0
        righta = s.count('a')
        ans = righta
        for c in s:
            if c == 'a':
                righta -= 1
            else:
                leftb += 1
            ans = min(ans, leftb + righta)
        return ans