------
## 最终结论
```python
from collections import Counter

def min_window(S, T):
    if not S or not T:
        return ""

    dict_t = Counter(T)
    required = len(dict_t)

    l, r = 0, 0
    formed = 0
    window_counts = {}
    min_len = float("inf")
    min_window = (0, 0)

    while r < len(S):
        character = S[r]
        window_counts[character] = window_counts.get(character, 0) + 1

        if character in dict_t and window_counts[character] == dict_t[character]:
            formed += 1

        # Move the right pointer to expand the window
        r += 1
        
        # Check if we have a valid window
        while l <= r and formed == required:
            character = S[l]

            # Update minimum window if needed
            if r - l < min_len:
                min_len = r - l
                min_window = (l, r)

            # Remove from the left side of the window
            window_counts[character] -= 1
            if character in dict_t and window_counts[character] < dict_t[character]:
                formed -= 1
            
            l += 1

    l, r = min_window
    return S[l:r] if min_len != float("inf") else ""
```