双层for循环
const repeatStrAndNumsByDoubleLoop = (str = 'aabbbcccddeeefffff') => { const res = { char: '', len: 0 } const { length } = str for(let i = 0; i < length; i++){ let charLen = 1 const curValue = str[i] for(let j = i + 1; j < length; j++){ const nextValue = str[j] if(curValue === nextValue){ charLen += 1 } if(curValue !== nextValue || j === length - 1){ if(charLen > res.len){ res.char = curValue res.len = charLen } i = j - 1 // 进行跳步 减少时间复杂度 break } } } return res }
双指针
正则
标签:字符,const,str,curValue,res,次数,length,charLen,字符串 From: https://www.cnblogs.com/zhenjianyu/p/17068483.html