Python Clean Solution


  • 0
    class Solution(object):
        def minWindow(self, s, t):
            table, match = {ch: t.count(ch) for ch in t}, len(t)
            ans, minlen = '', len(s)
            i, j = 0, 0
            while j < len(s):
                if s[j] in table:
                    table[s[j]] -= 1
                    if table[s[j]] >= 0:
                        match -= 1
                while match == 0:
                    if s[i] in table:
                        table[s[i]] += 1
                        if table[s[i]] > 0:
                            match += 1
                            if j-i+1 <= minlen:
                                minlen, ans = j-i+1, s[i:j+1]
                    i += 1                     
                j += 1
            return ans

Log in to reply
 

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