python写算法题:leetcode: 76. Minimum Window Substring

class Solution(object):
    def minWindow(self, s, t):
        """
        :type s: str
        :type t: str
        :rtype: str
        """
        ts=set(t)
        tcnt={}
        for tt in t:
            tv=tcnt.setdefault(tt, 0)
            tcnt[tt]=tv+1
        pos={}
        matchpos={}
        minp0=0
        minp1=len(s)
        scnt={}

        for p,c in enumerate(s):
            if c in ts:
                sv=scnt.setdefault(c, 0)
                scnt[c]=sv+1
                pos[(c,sv)]=p
                if scnt[c]>=tcnt[c]:
                    matchpos[c]=pos[(c,sv+1-tcnt[c])]
                if len(matchpos)==len(ts):
                    p0=min([v for k,v in matchpos.items()])
                    if p-p0

 

你可能感兴趣的:(算法,python)