Skip to content

Commit bd5ec25

Browse files
Refactor : Minimum Window Substring
1 parent 4973894 commit bd5ec25

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
from collections import Counter
22

33
class Solution:
4-
def minWindow(self, s, t):
4+
def minWindow(self, s: str, t: str) -> str:
55
need = Counter(t)
66
missing = len(t)
77
left = start = end = 0
8-
window = {}
9-
for right, char in enumerate(s, 1):
8+
for right, char in enumerate(s):
109
if need[char] > 0:
1110
missing -= 1
1211
need[char] -= 1
13-
if missing == 0:
14-
while left < right and need[s[left]] < 0:
15-
need[s[left]] += 1
16-
left += 1
12+
while missing == 0:
1713
if end == 0 or right - left < end - start:
18-
start, end = left, right
14+
start, end = left, right + 1
1915
need[s[left]] += 1
20-
missing += 1
16+
if need[s[left]] > 0:
17+
missing += 1
2118
left += 1
2219
return s[start:end]
2320

0 commit comments

Comments
 (0)