classSolution { public: conststaticint maxn = 1e5 + 10; conststaticint maxm = 1e5 + 10; conststaticint INF = 0x3f3f3f3f; unordered_map<char, int> mp; stringminWindow(string s, string t) { for (int i = 0; i < t.size(); ++i) { mp[t[i]]++; } int tmp = t.size(); // 窗口中缺少的个数 int left = 0; int ans = INF, l = -1, r = -1; for (int right = 0; right < s.size(); ++right) { if (mp.count(s[right])) { if (mp[s[right]] > 0) { tmp--; } mp[s[right]]--; } while (tmp == 0) { if (ans > right - left + 1) { ans = right - left + 1; l = left; r = right; } if (mp.count(s[left])) { mp[s[left]]++; if (mp[s[left]] > 0) { tmp++; } } left++; } } if (ans == INF) return""; else return s.substr(l, ans); } };