from collections import defaultdict classSolution(object): defminWindow(self, s, t): """ :type s: str :type t: str :rtype: str """ ifnot s: return"" ifnot t: return"" useddict = defaultdict(int) for char in t: useddict[char] += 1 length = len(t) minnum,start,end = len(s)+1,0,0 head = 0 for i in range(len(s)): if s[i] in useddict: useddict[s[i]] -= 1 if useddict[s[i]]>=0: length -= 1 while length==0: if i - start+1 < minnum: minnum = i-start+1 head = start if s[start] in useddict: useddict[s[start]] += 1 if useddict[s[start]] > 0: ## more same char was used length += 1 start += 1 return s[head:head+minnum] if minnum <= len(s) else""