1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| const int N = 100000; bool st[N]; class Solution { public: int maximumRemovals(string s, string p, vector<int>& removable) { auto check = [&](int mid) { for (int i = 0; i < s.size(); ++i) st[i] = false; for (int i = 0; i < mid; ++i) st[removable[i]] = true; int i = 0, j = 0; while (i < s.size() && j < p.size()) { if (st[i]) { ++i; continue; } if (s[i] == p[j]) ++j; ++i; } return j == p.size(); }; int l = 0, r = removable.size(); while (l < r) { int mid = l + r + 1 >> 1; if (check(mid)) l = mid; else r = mid - 1; } return r; } };
|