Minimum Window Substring(FB 模板)
Given a string source and a string target, find the minimum window in source which will contain all the characters in target.
Notice
If there is no such window in source that covers all characters in target, return the emtpy string"".
If there are multiple such windows, you are guaranteed that there will always be only one unique minimum window in source.
Clarification
Should the characters in minimum window has the same order in target?
Not necessary.
Example
For source ="ADOBECODEBANC", target ="ABC", the minimum window is"BANC"
分析
前向型追击指针,target和source都分别放入俩hash, 或者int[256],比较俩大小
要考虑有数字或者字符,所以用256而非26
还是按模板写吧。
第二种做法
http://blog.hyoung.me/cn/2017/02/minimum-window-substring/
还是双指针,只是判断source和target是否相等时,用sourceCount,。先用target初始化HashMap<Character, Integer> map
若遇到char在target中的,则sourceCount ++。同时target的hashmap里count--。
答案
python
2个dict存s,t的count,isvalid函数判断是否t在s内:sl[i] < tl[i]
前向追击指针,sdict,ldict count ++/--控制
根据模板写的
一个map存char count。头尾指针,尾前进到满足条件,头缩进到不满足条件。2个while一个头一个尾。注意min/max的位置
jiuzhang的模板做 for start,while end
Last updated
Was this helpful?