-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBruteForceApproch_MinimumWindowSubstring.cpp
More file actions
67 lines (55 loc) · 1.35 KB
/
BruteForceApproch_MinimumWindowSubstring.cpp
File metadata and controls
67 lines (55 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <string>
#include <vector>
#include <climits>
using namespace std;
class Solution {
public:
string minWindow(string s, string t) {
int l = 0;
int r = 0;
int sub_len = INT_MAX;
int st = -1;
int n = s.size();
int m = t.size();
int cnt = 0;
for(r=0;r<n;r++)
{
vector<int> ch(256, 0);
for(int j=0;j<m;j++)
{
ch[t[j]]++;
}
cnt=0;
for(int i=r ; i<n ; i++)
{
if(ch[s[i]]>0)
{
cnt++;
}
if(cnt==m)
{
if(i-r+1<sub_len)
{
sub_len=i-r+1;
st=r;
}
break;
}
}
}
return s.substr(st,sub_len );
}
};
int main() {
Solution sol;
string s = "ADOBECODEBANC";
string t = "ABC";
string result = sol.minWindow(s, t);
if (result.empty()) {
cout << "No window containing all characters of '" << t << "' found in '" << s << "'." << endl;
} else {
cout << "Minimum window substring is: \"" << result << "\"" << endl;
}
return 0;
}