Minimum Window Substring LeetCode solution in C++
1class Solution {2public:3string minWindow(string s, string t) {4unordered_map<char, int> ump;5for (auto i : t) {6ump[i]++;7}89int i = 0, j = 0, count = 0;10int ans = INT_MAX, answer = 0;11for (; j < s.size(); j++) {12if (ump[s[j]] > 0) {13count++;14}15ump[s[j]]--;16if (count == t.size()) {17while (i < j && ump[s[i]] < 0) {18ump[s[i]]++;19i++;20}21if (ans > j - i + 1) {22ans = j - i + 1;23answer = i;24}25ump[s[i]]++;26i++;27count--;28}29}30return ans == INT_MAX ? "" : s.substr(answer, ans);31}32};