Given a string S and a string T, find the minimum window in S which would contain all the characters in T in complexity O (n ).
for example,
S = "Adobecodebanc"
T = "ABC"
minimum window is "BANC" .
Note:
If There is no such window in S so covers all characters in T, return the emtpy string "" .
If There is multiple such windows, you is guaranteed that there would always being only one unique minimum window in S.
classSolution {
Private:
inthashs[ the];
inthasht[ the];
InlineBOOLCheck ()
{
for(intI=0;i< the; i++)
if(Hashs[i]returnfalse;
returntrue;
}
Public:
stringMinwindow (stringSstringT
{
for(intI=0;i< the; i++)
{
hashs[i]=0;
hasht[i]=0;
}
for(intI=0; I<t.size (); i++)
hasht[t[i]]++;
intminl=-1;
intMinr=s.length ();
for(intI=0; I<s.size (); i++)
hashs[s[i]]++;
if(!check ())return"";
intL=0;
intR=0;
for(intI=0;i< the; i++) hashs[i]=0;
hashs[s[0]]=1;
while(true)
{
if(check ())
{
if(R-L<MINR-MINL)
{
Minl=l;
Minr=r;
if(minr-minl+1==t.length ()) Break;
}
hashs[s[l]]--;
l++;
}
Else
{
r++;
if(R==s.length ()) Break;
hashs[s[r]]++;
}
}
if(minl==-1)return"";
Else returnS.substr (minl,minr-minl+1);
}
};