class Solution:
def minWindow(self, s: str, t: str) -> str:
def judge(map_p, map_q):
for key, value in map_q.items():
if map_p.get(key, 0) < value:
return False
return True
n = len(s)
m = len(t)
map_t = {}
for c in t:
map_t[c] = map_t.get(c, 0) + 1
map_s = {}
min_len = float("inf")
left = 0
res_left = -1
res_right = -1
for right in range(n):
map_s[s[right]] = map_s.get(s[right], 0) + 1
while right - left + 1 >= m and judge(map_s, map_t):
if right - left + 1 < min_len:
min_len = right - left + 1
res_left = left
res_right = right
map_s[s[left]] = map_s.get(s[left], 0) - 1
left += 1
if min_len == float("inf"):
return ""
else:
return s[res_left : res_right + 1]
标签:子串,map,right,min,Python,res,最小,len,left
From: https://www.cnblogs.com/DCFV/p/18417998