problem
solution
- native , TLE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22class Solution {
public:
bool isSubseq(string s, string p){
int n = s.size(), m=p.size();
if(m>n) return false;
int j = 0;
for(int i=0;i<n;++i){
if(p[j] == s[i]) j++;
}
return j==m;
}
int maximumRemovals(string s, string p, vector<int>& removable) {
// native
int ret = 0 , n = removable.size();
for(int i=0;i<n;++i){
s[removable[i]] = '#';
if(isSubseq(s,p)) ret= i+1;
else break;
}
return ret;
}
};
option 1
1 | class Solution { |
analysis
- time complexity
O(logn)
- space complexity
O(1)