File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+ using namespace std ;
3+ class Solution {
4+ public:
5+ string minWindow (const string &s , const string &pattern){
6+ unordered_map<char , int >st,pt;
7+ for (auto &itr:pattern){
8+ pt[itr]++;
9+ }
10+ int start = 0 , end_ = s.size (), i=0 ;
11+ int min_window =INT_MAX;
12+ string ans;
13+ int win_size=0 ;
14+ list<char >q;
15+ while (i<end_){
16+ st[s[i]]++;
17+ q.push_back (s[i]);
18+ if (pt.find (s[i])!=pt.end ()){
19+ win_size++;
20+ }
21+ if (win_size >= (int )pattern.size ()){
22+ while (start < i && (pt.find (s[start])==pt.end () || st[s[start]]-1 >=pt[s[start]])){
23+ st[s[start]]--;
24+ q.pop_front ();
25+ ++start;
26+ }
27+ string temp (q.begin () , q.end ());
28+ if (ans.size ()==0 || temp < ans){
29+ ans = temp;
30+ }
31+ min_window = min (min_window , i - start +1 );
32+ }
33+ ++i;
34+ }
35+ return ans;
36+ }
37+ };
38+ int main (void ){
39+ Solution s1;
40+ cout << s1.minWindow (" figehaeci" ," aei" ) << ' \n ' ;
41+ return 0 ;
42+ }
You can’t perform that action at this time.
0 commit comments