Skip to content

Commit b8f62dd

Browse files
authored
Merge pull request #80 from InflixOP/patch1
Create #76. Minimum Window Substring.cpp
2 parents a66f2f8 + e7f63e8 commit b8f62dd

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

#76. Minimum Window Substring.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Solution {
2+
public:
3+
string minWindow(string s, string t) {
4+
unordered_map<char,int> mp;
5+
for(int i=0;i<t.length();i++){
6+
mp[t[i]]++;
7+
}
8+
int l=0,r=0;
9+
int c=0,mini=INT_MAX,si=-1;
10+
while(r<s.length()){
11+
if(mp[s[r]]>0)
12+
c++;
13+
mp[s[r]]--;
14+
while(c==t.length()){
15+
if(r-l+1<mini){
16+
mini=r-l+1;
17+
si=l;
18+
}
19+
mp[s[l]]++;
20+
if(mp[s[l]]>0)
21+
c--;
22+
l++;
23+
}
24+
r++;
25+
}
26+
if(si==-1)
27+
return "";
28+
else
29+
return s.substr(si,mini);
30+
}
31+
};

0 commit comments

Comments
 (0)