class Solution {
public:
map<char, int> maps, mapt;
bool isContained(){
for(pair<char, int> elem : mapt){
if(elem.second > maps[elem.first]) return false;
}
return true;
}
string minWindow(string s, string t) {
int left = 0, right = 0;
int minLength = INT_MAX, ansL = -1;
for(int i = 0; i < t.size(); ++i) ++mapt[t[i]];
while(left <= right && right < s.size()){
++maps[s[right]];
if(mapt.find(s[right]) != mapt.end()){
while(isContained()){
if(minLength > right - left + 1){
minLength = right - left + 1;
ansL = left;
}
--maps[s[left++]];
}
}
++right;
}
if(ansL == -1) return string("");
return s.substr(ansL, minLength);
}
};
标签:子串,right,return,string,++,最小,76,ansL,left From: https://www.cnblogs.com/llllmz/p/18415595