Skip to content

Commit 392aa7b

Browse files
authored
Create minimum-deletions-to-make-string-balanced.cpp
1 parent d5332ac commit 392aa7b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int minimumDeletions(string s) {
7+
int result = 0, b_cnt = 0;
8+
for (const auto& c : s) {
9+
if (c == 'b') {
10+
++b_cnt;
11+
} else if (b_cnt) {
12+
--b_cnt;
13+
++result;
14+
}
15+
}
16+
return result;
17+
}
18+
};

0 commit comments

Comments
 (0)