LeetCode--Minimum Window Substring
2020-12-13 05:55
标签:style blog http color io for art ar 这题关键注意:T可能有重复,所以得统计次数,我之前理解错了,后来参考别人代码才知道的。 思路就是双指针+字符hash,具体见注释 http://blog.csdn.net/jellyyin/article/details/10313827 这个比较清晰,解释的。不需要用map,因为那样就成了O(nlogn)了 LeetCode--Minimum Window Substring,搜素材,soscw.com LeetCode--Minimum Window Substring 标签:style blog http color io for art ar 原文地址:http://www.cnblogs.com/cane/p/3889533.html 1 class Solution {
2 public:
3 string minWindow(string S, string T) {
4 int data[260],i,j;
5 memset(data,0,sizeof(data));
6 for(i=0;i
//这里的意思就是还没找到包含T所有字符的window的时候就增加右指针
12 if(numT.length())
13 {
14 if(now[S[i]];
15 now[S[i]]++;
16 }
//找到一个窗口
17 if(num==T.length())
18 {
//先把窗口前面的
19 while(j1>=data[S[j]])
20 {
21 --now[S[j]];
22 ++j;
23 }
24 if(minn>i-j+1)left=j,right=i,minn=i-j+1;
25
26 while(jT.length())
27 {
28 now[S[j]]--;
29 if(now[S[j]];
30 ++j;
31 }
32 }
33 }
34 string temp;
35 if(minn129)return temp.assign(S,left,right-left+1);
36 else return "";
37 }
38 };
文章标题:LeetCode--Minimum Window Substring
文章链接:http://soscw.com/essay/31991.html