76. Minimum Window Substring (Hard) - TengnanYao/daily_leetcode GitHub Wiki
class Solution(object):
def minWindow(self, s, t):
"""
:type s: str
:type t: str
:rtype: str
"""
h = collections.Counter(t)
result = ""
i = 0
count = len(h)
for j, c in enumerate(s):
if c in h:
h[c] -= 1
if h[c] == 0:
count -= 1
if count == 0:
while True:
val = s[i]
if val in h:
h[val] += 1
i += 1
if h[val] > 0:
if not result or len(result) > j - i + 1:
result = s[i - 1 : j + 1]
count += 1
break
return result