leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1653.cpp (497B)
0 class Solution {
1 public:
2 int minimumDeletions(const string &s) const {
3 static int acount[100001];
5 const int n = s.size();
6 acount[n] = 0;
7 for (int i = n - 1; i >= 0; i--) {
8 acount[i] = acount[i + 1] + (s[i] == 'a');
9 }
11 int acnt = 0, bcnt = 0, res = acount[0];
12 for (int i = 0; i < n; i++) {
13 s[i] == 'a' ? acnt++ : bcnt++;
14 res = min(res, bcnt + acount[i] - 1);
15 }
17 return res;
18 }
19 };