https://oj.leetcode.com/problems/minimum-window-substring/
Under the constraints of linear complexity, consider using the sliding window method. The idea of this approach is to maintain a window that expands to the right edge to meet the constraints. The left edge of the window shrinks to minimize it.
Note that this topic may be an implementation of a typical sliding window approach. The outer loop moves the left boundary I, and the loop expands the right boundary p to meet the constraints. And both inside and outside have termination possibilities.
Use two map and a count variable to quickly statistic the conditions of the condition to be satisfied.
Class Solution {Public:int n,m;string Minwindow (String S, String T) {map <char,int> cm;map <char,int> stat;n=s . Length (); M=t.length (); for (int i=0;i<m;i++) {if (Cm.find (T[i]) ==cm.end ()) {cm[t[i]]=1;} else{cm[t[i]]++;} stat[t[i]]=0;} int Res=numeric_limits<int>::max (); typedef pair <int,int> Scpair;scpair minw;int q=0;int count=0;for (int i =0;i<n;i++) {bool Endflag=false;while (count<m) {q++;if (q>n) {endflag=true;break;} if (Cm.find (S[q-1]) ==cm.end ()) {continue;} if (Stat[s[q-1]]<cm[s[q-1]]) {count++;} stat[s[q-1]]++;} if (Endflag) {break;} if (res > Q-i) {res=q-i;minw=scpair (i,q); } if (Cm.find (S[i]) ==cm.end ()) {continue;} Stat[s[i]]--;if (Stat[s[i]]<cm[s[i]]) {count--;}} if (res>n) {return "";} No Winreturn s.substr (Minw.first,minw.second-minw.first);};
Leetcode-minimum window substring-Minimum Windows sub-string-sliding window algorithm (ruler method)