Given astring S andastring T, find the minimum window in S which will contain all thecharactersin T in complexity O(n).
For example,
S = "ADOBECODEBANC"
T = "ABC"
Minimum window is "BANC".
classSolution(object):defminWindow(self, s, t):
need, missing = collections.Counter(t), len(t)
i = I = J = 0for j, c in enumerate(s, 1):
missing -= need[c] > 0
need[c] -= 1ifnot missing:
while i < j and need[s[i]] < 0:
need[s[i]] += 1
i += 1ifnot J or j - i <= J - I:
I, J = i, j
return s[I:J]
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).For example,S = "ADOBECODEBANC"T = "ABC"Minim