Medium
Minimum String Length After Balanced Removals — Python
Full explanation · Time O(n) · Space O(1)
# Time: O(n)
# Space: O(1)
# string
class Solution(object):
def minLengthAfterRemovals(self, s):
"""
:type s: str
:rtype: int
"""
return abs(s.count('a')-s.count('b'))