R7-子串篇
class Solution:
def minWindow(self, s: str, t: str) -> str:
ret_left,ret_right=-1,len(s)
left=0
#s子串字母出现的次数
cnt_s=Counter()
#t中字母出现的次数
cnt_t=Counter(t)
for right,c in enumerate(s):
cnt_s[c]+=1
while cnt_s>=cnt_t:
#找到更短的子串
if right-left<ret_right-ret_left:
ret_left,ret_right=left,right
cnt_s[s[left]]-=1
left+=1
return ""if ret_left<0 else s[ret_left:ret_right+1]