没有重复字符的最长连续子串
- abcabcbb => 3 (abc)
- bbbbbbbb => 1 (b)
- pwwkew => 3 (wke)
- acdaebd => 5 (cdaeb)
- aaaaaabc => 3(abc)
var str = "abc"
function getNoRepeatStr(str) {
const strarr = str.split("")
let result = []
strarr.forEach((s1, i1) => {
if(result.length > strarr.length - i1){
return
}
let tempResult = []
for (var i = i1; i < strarr.length; i++) {
let tempS = strarr[i]
if (tempResult.indexOf(tempS) == -1) {
tempResult.push(tempS)
}else{
break
}
}
if (result.length < tempResult.length) {
result = tempResult
}
})
return result
}
getNoRepeatStr(str)
本文标题:没有重复字符的最长连续子串
本文链接:https://www.haomeiwen.com/subject/qmatsqtx.html
网友评论