import "math"
/**
  * 
  * @param S string字符串 
  * @param T string字符串 
  * @return string字符串
*/
func minWindow( S string ,  T string ) string {
    need, window := map[byte]int{}, map[byte]int{}
    for i, _ := range T {
        need[T[i]]++
    }
    left, right := 0, 0
    start, length := 0, math.MaxInt32
    vaild := 0
    
    for right < len(S) {
        c := S[right]
        right++
        if _, ok := need[c]; ok {
            window[c]++
            if window[c] == need[c] {
                vaild++
            }
        }
        for vaild == len(need) {
            if right - left < length {
                start = left
                length = right - left
            }
            d := S[left]
            left++
            if _, ok := need[d]; ok {
                if window[d] == need[d] {
                    vaild--
                }
                window[d]--
            }
            
        }
    }
    if length == math.MaxInt32 {
        return ""
    }
    return S[start:start+length]
}