76. Minimum Window Substring

来源:互联网 发布:情侣手环淘宝 互相感应 编辑:程序博客网 时间:2024/05/17 02:16
class Solution {public:    string minWindow(string s, string t) {        map<char,int> tmap,temp;string result;int begin,end;begin=end=0;int count=t.length();int min=s.length()+1;int finalStartPos=0;if(s.length()<t.length()||s.length()==0||t.length()==0)return result;for(int i=0;i<t.length();i++)tmap[t.at(i)]+=1;temp=tmap;    while(end<s.length()){  if(tmap[s.at(end)]>0)  {  temp[s.at(end)]--;  if(temp[s.at(end)]>=0)  count--;  if(count==0)  {while(true){if(tmap[s[begin]]>0){ if(temp[s[begin]]<0)  temp[s[begin]]++; else break;}begin++;}if (min > end - begin+ 1)                   {                         min =  end - begin+ 1; finalStartPos = begin;                   }  }//if  }//ifend++; }//whileif(min==s.length()+1)return result;result.assign(s,finalStartPos,min);   return result;      }};

0 0
原创粉丝点击