python sliding window solution


  • 0
    A
    class Solution:
        def minWindow(self, s, t):
            """
            :type s: str
            :type t: str
            :rtype: str
            """
            arr = [0] * 128
            for c in t:
                arr[ord(c) - ord('A')] += 1
                
            i = j = 0
            res = ''
            
            for j in range(len(s)):
                arr[ord(s[j]) - ord('A')] -= 1
                while max(arr) <= 0:
                    res = s[i:j+1] if res == '' or j+1 - i < len(res) else res
                    arr[ord(s[i]) - ord('A')] += 1
                    i += 1
                    
            return res
    

Log in to reply
 

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