SOURCE

function maxStr(s) {
    let str = ''; // 用来存放无重复子串
    let maxLength = 0;
    for (let i = 0; i < s.length; i++) {
        const char = s.charAt(i); // 获取当前字符
        const index = str.indexOf(char); // 获取索引
        if (index === -1) {
            // 说明没出现了重复字符
            str = str + char;
        } else {
            // 说明出现了重复字符,要把前面的到索引这的子串删掉
            str = str.slice(index + 1) + char;
        }
        maxLength = maxLength > str.length ? maxLength : str.length;
    }
    return maxLength
}

console.log(maxStr('abbcbcscsd'))
console 命令行工具 X clear

                    
>
console