File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ from collections import defaultdict
2+
3+ class Solution :
4+ def minWindow (self , s : str , t : str ) -> str :
5+ char_frequency = defaultdict (lambda : 0 )
6+ for c in pattern :
7+ char_frequency [c ] += 1
8+ chars_matched = 0
9+
10+ start = 0
11+ res = ""
12+
13+ for end in range (len (string )):
14+ right_char = string [end ]
15+ if right_char in pattern :
16+ char_frequency [right_char ] -= 1
17+ if char_frequency [right_char ] == 0 :
18+ chars_matched += 1
19+
20+ while start <= end and chars_matched == len (char_frequency ):
21+ if res == "" or end - start + 1 < len (res ):
22+ res = string [start :end + 1 ]
23+
24+ left_char = string [start ]
25+ if left_char in pattern :
26+ if char_frequency [left_char ] == 0 :
27+ chars_matched -= 1
28+ char_frequency [left_char ] += 1
29+ start += 1
30+
31+ return res
You can’t perform that action at this time.
0 commit comments