# Minimum Window Substring

Source: Internet
Author: User

Minimum Window substring Topic
Analytical
``//76. Minimum Window Substringclasssolution_76 { Public://1) begin points to 0, end moves back until the Begin-end interval contains all the characters in T. Record window length d    //2) and then begin to remove the element until the removed character is the character in T is stopped, and a character in T is not included in the window,    //3) continues to move end until all the characters in T are included in the window, re-record the smallest window d.     //4) So loop to know the last character in the end to S.     //Time complexity of O (n)String Minwindow_ (string s, String t) {string result;if(S.empty () | | S.size () <t.size ()) {returnResult } unordered_map<Char,int> MP;//store characters in T for easy matching with s        intleft =0;intCNT =0;//Window string to count        intMinlen = S.size ()+1; for(inti =0;        I < t.size (); i++) {mp[t[i]]++; } for(intright =0; Right < S.size (); right++) {if(Mp.find (S[right])!=mp.end ())//t characters in left~right window{if(mp[s[right]]>0)//Experience the role of >0: when there are repeating strings in S, the first match{cnt++;//Counter +1} mp[s[right]]--;//When there are duplicate elements, it may be reduced to negative                 while(Cnt==t.size ())////When all the characters of T are inside the window, start moving the left window{if(Mp.find (S[left])!=mp.end ()) {if(Minlen>right-left+1) {Minlen = Right-left +1; result = S.substr (left, Right-left +1); } mp[s[left]]++;//include it in MP and continue to find                        if(mp[s[left]]>0) {cnt--; }} left++;//Right Shift window to the left}            }        }returnResult } string Minwindow (string s, String t) {string s, T;returnMinwindow_ (S, T); }};``
Source of the topic
• Minimum Window Substring

Minimum Window Substring

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.