Python simple solution


  • 0
    A
    class Solution(object):
        def minWindow(self, s, t):
            """
            :type s: str
            :type t: str
            :rtype: str
            """
    
            dic = collections.Counter(t)
            l = r = 0
            res = s+"#"
            
            while r <= len(s):
    
                if all((0>=dic[i] for i in dic)):
                    res = min(res,s[l:r],key=len)
                    
                    if s[l] in dic:
                        dic[s[l]]+=1
                    l+=1
                    
                else:
                    if r<len(s) and s[r] in dic: 
                        dic[s[r]]-=1
                    r+=1
        
            return res if res[-1]!="#" else ""
            
            
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.