76. Minimum Window Substring
使用了之前sliding window的范式
1 | class Solution { |
filtered
只记录存在于t中的字符的坐标
1 | class Solution { |
review 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33class Solution {
public:
string minWindow(string s, string t) {
int n = s.size();
unordered_map<char, int> map;
for(auto ch : t)
++map[ch];
int count = map.size();
int begin = 0, end = 0;
int rl = 0;
int subSize = INT_MAX;
while(end < n)
{
if(--map[s[end]] == 0)
--count;
while(count == 0)
{
if(end - begin + 1 < subSize)
{
rl = begin;
subSize = end - begin + 1;
}
if(++map[s[begin]] > 0)
++count;
++begin;
}
++end;
}
if(subSize == INT_MAX)
return "";
return s.substr(rl, subSize);
}
};