LeetCode刷题:76. Minimum Window Substring
原题链接:https://leetcode.com/problems/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.
给定一个字符串 S 和一个字符串 T,请在 S 中找出包含 T 所有字母的最小子串。
示例:
输入: S = "ADOBECODEBANC", T = "ABC"
输出: "BANC"
说明:
如果 S 中不存这样的子串,则返回空字符串 ""。
如果 S 中存在这样的子串,我们保证它是唯一的答案。
算法设计
下面是参考LeetCode讲解的算法设计:
这个问题要求我们返回字符串S中的最小窗口,它包含字符串T的所有字符。如果一个窗口包含有T的所有字符,我们就称它为"期望窗口"。
我们可以使用一个简