We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6caaacd commit 3d16449Copy full SHA for 3d16449
0076-minimum-window-substring/0076-minimum-window-substring.cpp
@@ -0,0 +1,52 @@
1
+class Solution
2
+{
3
+public:
4
+ string minWindow(string s, string t)
5
+ {
6
+ unordered_map<char, int> mp;
7
+ for (int i = 0; i < t.size(); i++)
8
9
+ mp[t[i]]++;
10
+ }
11
+ int count = mp.size();
12
+ string ans;
13
+
14
+ int mini = INT_MAX;
15
16
+ int i = 0;
17
+ int j = 0;
18
19
+ while (j < s.size())
20
21
22
+ if (mp.find(s[j]) != mp.end())
23
24
+ mp[s[j]]--;
25
+ if (mp[s[j]] == 0)
26
27
+ count--;
28
29
30
31
+ while (count == 0)
32
33
+ if (mini > j - i + 1)
34
35
+ mini = min(mini, j - i + 1);
36
+ ans = s.substr(i, j - i + 1);
37
38
+ if (mp.find(s[i]) != mp.end())
39
40
+ mp[s[i]]++;
41
+ if (mp[s[i]] == 1)
42
43
+ count++;
44
45
46
+ i++;
47
48
+ j++;
49
50
+ return ans;
51
52
+};
0 commit comments