Minimum Window Substring
Minimum Window Substring
Problem Description
Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window. If there is no such substring, return the empty string "".
The testcases will be generated such that the answer is unique.
Intuition
We need to find the shortest substring of s that contains all characters from t.
Store the character frequencies of t in a hash map, then use a sliding window to find the minimum substring.
Track how many unique characters have been fully satisfied in the current window.
Algorithm
1 | class Solution { |
本部落格所有文章除特別聲明外,均採用CC BY-NC-SA 4.0 授權協議。轉載請註明來源 YouChen's Blog!