We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4973894 commit bd5ec25Copy full SHA for bd5ec25
minimum-window-substring/printjin-gmailcom.py
@@ -1,23 +1,20 @@
1
from collections import Counter
2
3
class Solution:
4
- def minWindow(self, s, t):
+ def minWindow(self, s: str, t: str) -> str:
5
need = Counter(t)
6
missing = len(t)
7
left = start = end = 0
8
- window = {}
9
- for right, char in enumerate(s, 1):
+ for right, char in enumerate(s):
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
+ while missing == 0:
17
if end == 0 or right - left < end - start:
18
- start, end = left, right
+ start, end = left, right + 1
19
need[s[left]] += 1
20
- missing += 1
+ if need[s[left]] > 0:
+ missing += 1
21
left += 1
22
return s[start:end]
23
0 commit comments