2021-08-08 20:59
中国海洋大学 前端工程师 牛客31504102...:function maxLengthBetweenEqualCharacters (str) {
str = str.trim()
let arr = []
let max = 0
for(let i = 0; i<str.length; i++){
if(!arr.includes(str.charAt(i))){
arr.push(str.charAt(i)) // 如果之前没有就进栈
let j = str.lastIndexOf(str.charAt(i)) // 找出从尾部匹配的一项
if(j !== i){ // 判断出现的位置是不是和当前的一直
max = max > j - i - 1 ? max : j - i - 1
}
}
}
return max
}
不用分割数组
0 点赞 评论 收藏
分享
创作者周榜
更多
关注他的用户也关注了: