C++ post referred to top voted post
First, thanks the post from @vinceyuan\n\nHere I just try explain it carefully so to help some beginners to better understand the inspiring ideas behind the sol
First, thanks the post from @vinceyuan\n\nHere I just try explain it carefully so to help some beginners to better understand the inspiring ideas behind the solution.\n\nPreprocessing step:\n\nstore the condition variable in the unordered_map\n\nWhile loop step:\n\n       check sub-conditions, update global variable\n\n       for the satisfying condition, we can move the start pointer \n       forward to calculate all the possible solution.\n\nI do think this solution is really not easy to us to implement all by our self. \n\nThe only way to better grasp this solution is to write it many times by yourself.\n\nHere is the C++ implementation:\n\n\n    class Solution {\n    public:\n        string minWindow(string s, string t) {\n            vector<int> v(128, 0);\n            for(auto c:t) v[c]++;\n            int start=0, end=0, counter=t.size();\n            int minStart=0, minLen=INT_MAX;\n            int len=s.size();\n            while(end<len){\n                if(v[s[end]]>0)  counter--;\n                v[s[end]]--;\n                end++;\n                while(counter==0){\n                    if(end-start<minLen){\n                        minStart=start;\n                        minLen=end-start;\n                    }\n                    v[s[start]]++;\n                    if(v[s[start]]>0)  counter++;\n                    start++;\n                }\n            }\n            if(minLen!=INT_MAX)\n                return s.substr(minStart, minLen);\n            return "";\n        }\n    };
[]