727. Minimum Window Subsequence
https://leetcode.com/problems/minimum-window-subsequence/
Given strings S
and T
, find the minimum (contiguous) substring W
of S
, so that T
is a subsequence of W
.
If there is no such window in S
that covers all characters in T
, return the empty string ""
. If there are multiple such minimum-length windows, return the one with the left-most starting index.
Example 1:
Note:
All the strings in the input will only contain lowercase letters.
The length of
S
will be in the range[1, 20000]
.The length of
T
will be in the range[1, 100]
.
给定S和T, 问S中包含以T为subseq的最小substr是什么。argmin + substr=>滑动窗口 or DP。和常见的string match问题类似,dp[i][j]存以i为底的最短的S的substr能匹配T[:j]的长度。分为S[i]和T[j]是否相等两种情况。最后再遍历找以不同S[i] dp[i][N]的最小值为全局最优,用底减去长度为对应的substr。
Last updated
Was this helpful?