ForeveHG / Frontend-Daily-Interview

学习,尝试回答一些前端面试题
1 stars 0 forks source link

92. 给定一个字符串,找出其中无重复字符的最长子字符串长度 #93

Open ForeveHG opened 3 years ago

ForeveHG commented 3 years ago
function findStr(str) {
    str = str.split('');
    let current = []
    let result = []
    while(str.length > 0) {
        if(current.indexOf(str[0]) == -1) {
            current.push(str[0])
            str = str.slice(1)
        } else {
            result.push(current.join(''));
            current = []
        }
    }
    return result.sort((a,b) => b.length - a.length)[0];
}

//测试
findStr('pwwkew') //wke