-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path76.py
30 lines (23 loc) · 752 Bytes
/
76.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import re
import collections
import itertools
import heapq
import bisect
class Solution:
def minWindow(self, s: str, t: str) -> str:
need = collections.Counter(t)
missing = len(t)
left = start = end = 0
for right, char in enumerate(s, 1):
missing -= need[char] > 0
need[char] -= 1
if missing == 0:
while left < right and need[s[left]] < 0:
need[s[left]] += 1
left += 1
if not end or right - left <= end - start:
start, end = left, right
# need[s[left]] += 1
# missing += 1
# left += 1
return s[start:end]