interfaceIres{
char:string
length:number}functionfn(str:string):Ires{let res :Ires ={
char:'',
length:0}const len = str.length
if(len ===0)return res
let tempLength =0//临时记录连续字符串的长度let i =0let j =0for(; i < len; i ++){if(str[i]=== str[j]){
tempLength++}if(str[i]!== str[j]|| i === length -1){
res.char = str[j]
res.length = tempLength
}
tempLength =0if(i < len -1){
j = i //让 j 追上 i
i--//细节 }}}
获取字符串中字符串连续最多的字符以及次数如 输入 ‘abbcccddeeee1234’连续最多的字符是 e ,4次双指针解法定义指针 i 和 j 。j 不动,i 继续移动如果 i 和 j 的值一直相等,则 i 继续移动直到 i 和 j 的值不相等,记录处理,让 j 追上 i ;继续第一步interface Ires { char:string length:number}function fn(str:string):Ires{ let res :Ires = {