SOURCE

function minWindow(s, t) {
    //双指针实现滑动窗口
    //初始left和right从0开始,right先逐步后移,直至窗口中的字符满足要求,
    //然后left逐步右移,直至窗口中的字符不满足要求
    //满足要求就比较窗口长度,如果小于原来长度就更新当前left值和窗口长度
    //重复right右移、left右移操作,直至right超出长度
    let left = 0;
    let right = 0;
    let start = 0;
    let length = Infinity;
    let sym = false;
    let map = new Map;
    t.split('').forEach(item => {
        map.has(item) ? map.set(item, map.get(item) + 1) : map.set(item, 1);
    })
    let str = s[0];
    if(map.has(str)) {
        map.set(str, map.get(str) - 1);
    }
    sym = reduce(map);
    while(right < s.length) {
        if(!sym) {
            console.log('1')
            right++;
            let str = s[right];
            if(map.has(str)) {
                map.set(str, map.get(str) - 1);
                sym = reduce(map);
            }
            console.log(sym, left, right)
        }else {
            console.log('2')
            if(right - left + 1 < length) {
                length = right - left + 1;
                start = left;
            }
            let str = s[left];
            if(map.has(str)) {
                map.set(str, map.get(str) + 1);
                sym = reduce(map);
            }
            left++;
            console.log(sym, left, right)
        }
    }
    function reduce(map) {
        let arr = [];
        arr = [...map.values()];
        return arr.every((item) => {
            return item <= 0 
        })
    }
    return s.substr(start, length)
};
let s = "ADOBECODEBANC"
let t = "ABC"
console.log(minWindow(s,t))
console 命令行工具 X clear

                    
>
console