Minimum Window Substring

Medium (Trung bình) Python 🔗 Xem trên LeetCode

📋 Đề Bài

Chưa có mô tả.

🧠 Thuật Toán & Kỹ Thuật

Hash Table (Bảng băm)
⏱️ Thời gian O(n)
💾 Không gian O(1)

💻 Lời Giải

Python 0076-minimum-window-substring.py
class Solution:
    def minWindow(self, s: str, t: str) -> 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]