Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- string minWindow(string s, string t) {
- unordered_map<char, int> count;
- for(char c: t) count[c]++;
- int counter=t.size(), left, right;
- int ans=INT_MAX, idx=0;
- for(left=0, right=0; right<s.size(); right++){
- if(count[s[right]]-- > 0) counter--;
- while(counter == 0){
- if(right-left+1 < ans){
- ans = min(ans, right-left+1);
- idx = left;
- }
- if(count[s[left++]]++ == 0) counter++;
- }
- }
- return ans==INT_MAX ? "" : s.substr(idx,ans);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement