Skip to content

Commit 0e1d17f

Browse files
authored
Create minimum-deletions-to-make-string-balanced.py
1 parent 392aa7b commit 0e1d17f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def minimumDeletions(self, s):
6+
"""
7+
:type s: str
8+
:rtype: int
9+
"""
10+
result = b_cnt = 0
11+
for c in s:
12+
if c == 'b':
13+
b_cnt += 1
14+
elif b_cnt:
15+
b_cnt -= 1
16+
result += 1
17+
return result

0 commit comments

Comments
 (0)