76. Minimum Window Substring

来源:互联网 发布:ubuntu mendelay 编辑:程序博客网 时间:2024/06/03 21:14
class Solution(object):
    def minWindow(self, s, t):
        """
        :type s: str
        :type t: str
        :rtype: str
        """
        need, missing = collections.Counter(t), len(t)
        i = I = J = 0
        for j, c in enumerate(s, 1):
            missing -= need[c]>0
            need[c] -= 1
            if not missing:
                while i < j and need[s[i]] < 0:
                    need[s[i]] += 1
                    i += 1
                if not J or j - i <= J - I:
                    I, J = i, j

        return s[I:J]


https://discuss.leetcode.com/topic/20692/12-lines-python/2

原创粉丝点击