Minimum Window Substring
基本忘记了,重点做
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).
Example:
Input: S = "ADOBECODEBANC", T = "ABC"
Output: "BANC"Note:
If there is no such window in S that covers all characters in T, return the empty string
"".If there is such window, you are guaranteed that there will always be only one unique minimum window in S.
- 我们最开始先扫描一遍T,把对应的字符及其出现的次数存到数组中。
- 然后开始遍历S,就把遍历到的字母对应的HashMap中的value减一,如果减1后仍大于等于0,total自增1。
- 如果total等于T串长度时,开始循环,纪录一个字串并更新最小字串值。然后将子窗口的左边界向右移,如果某个移除掉的字母是T串中不可缺少的字母,那么total自减1,表示此时T串并没有完全匹配。
Last updated