Topic:
Given a string S and a string T, find the minimum window in S which would contain all the characters in T in complexity O (n ).
for example,
s = " Adobecodebanc "
t = < Code style= "Font-family:monaco,menlo,consolas, ' Courier New ', monospace; font-size:13px; PADDING:2PX 4px; Color:rgb (199,37,78); White-space:nowrap; Background-color:rgb (249,242,244) ">" ABC "
Minimum window is "BANC" .
Note:
If There is no such window in S so covers all characters in T, return the emtpy string "" .
If There is multiple such windows, you is guaranteed that there would always being only one unique minimum window in S.
Idea: Use two pointers, a hash table, two pointers in order to record the width, the hash table in order to record the existence of the target character in the two pointers appear between the number of times, until all the characters appear in the string, moving the preceding pointer, until a character appears in the substring once, So the length of the space is the shortest, so the traversal is done until all the strings are traversed.
#include <iostream> #include <vector> #include <string>using namespace std;/* A string can contain the minimum length of substrings of all letters in another string */String MinLength (string& src,string& dest) {int I=0,j=0;int flag =0;int len= Src.size (); int pos=0;vector<int> hash (26,-1); for (I=0;i<dest.length (); i++) hash[dest[i]-' A '] =0;//for (i=0; I
Minimum Window Substring--Leetcode