
点这里
思路分析双指针(+哈希表)
双指针维护
[
j
,
i
]
[j,i]
[j,i]区间,哈希表
s
s
s存区间内每个字符出现的次数;哈希表
t
t
t预处理出t中每个字符出现次数。
c
n
t
cnt
cnt为表
s
s
s中有效字符的总个数(有效定义为:
s
s
s中每个字符在出现次数不超过
t
t
t中对应次数的前提下的,所有字符出现次数之和)
class Solution {
public:
string minWindow(string s, string t) {
unordered_map hashs,hasht;
for(auto c:t) hasht[c]++;
string ans;
int cnt=0;
for(int i=0,j=0;ihasht[s[j]]) hashs[s[j++]]--;
if(cnt==t.size())
if(i-j+1