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 } 不用分割数组