1def min_window(s, t):2 best_l = -13 best_len = float('inf')4 count_t, count_s = {}, {}5 for c in t:6 count_t[c] = 1 + count_t.get(c, 0)7 need = len(count_t)8 have = 09 l = 010 for r in range(len(s)):11 c = s[r]12 count_s[c] = 1 + count_s.get(c, 0)13 if c in count_t and count_s[c] == count_t[c]:14 have += 115 while have == need:16 if (r - l + 1) < best_len:17 best_l = l18 best_len = r - l + 119 c = s[l]20 count_s[c] -= 121 if c in count_t and count_s[c] < count_t[c]:22 have -= 123 l += 124 return s[best_l:best_l + best_len] if best_len != float('inf') else ""