// 字符串中最长的不重复的数组
function maxString(str) {
if (typeof (str) == 'string') {
let newStr = "";
let maxStr = ""
let maxLeng = 0;
let length = 0;
for (let i = 0; i < str.length; i++) {
if (newStr.indexOf(str[i]) == -1) {
newStr = newStr.concat(str[i])
length = newStr.length
} else {
if (length > maxLeng) {
maxLeng = length
maxStr = newStr
}
newStr = ""
length = 0;
}
}
return [maxStr, maxLeng]
} else {
return "数据类型不符"
}
}
输出字符串中不重复的最长的子字符串或长度
最新推荐文章于 2021-09-19 20:11:49 发布