76.Minimum-Window-Substring
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.代码
Approach #1 Sliding Window
双指针 + 双字典 (需要匹配的字典,窗口内的字典)
固定左边l, r++往右构建满足条件的map
当满足条件,固定右边r,l++缩小右端检查是否满足map
Time Complexity && Space Complexity: O(|S| + |T|)
Approach #2 Optimized Sliding Window
Last updated
Was this helpful?