Skip to content

Commit 4973894

Browse files
Solve : Minimum Window Substring
1 parent f83b231 commit 4973894

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from collections import Counter
2+
3+
class Solution:
4+
def minWindow(self, s, t):
5+
need = Counter(t)
6+
missing = len(t)
7+
left = start = end = 0
8+
window = {}
9+
for right, char in enumerate(s, 1):
10+
if need[char] > 0:
11+
missing -= 1
12+
need[char] -= 1
13+
if missing == 0:
14+
while left < right and need[s[left]] < 0:
15+
need[s[left]] += 1
16+
left += 1
17+
if end == 0 or right - left < end - start:
18+
start, end = left, right
19+
need[s[left]] += 1
20+
missing += 1
21+
left += 1
22+
return s[start:end]
23+

0 commit comments

Comments
 (0)