76. Minimum Window Substring

76. Minimum Window Substring

class Solution:
    def minWindow(self, s: str, t: str) -> str:
        counts=defaultdict(int)
        for c in t:
            counts[c]+=1

        begin=0
        end=0
        best_len=sys.maxsize
        best_begin=-1

        sums=len(t)

        while end=0:
                sums-=1
            end+=1
            while sums==0:
                if end-begin<=best_len:
                    best_len=end-begin
                    best_begin=begin
                counts[s[begin]]+=1
                if counts[s[begin]]>0:
                    sums+=1
                begin+=1
        if best_begin==-1:return ''
        return s[best_begin:best_begin+best_len]
                

你可能感兴趣的:(leetcode)