<script> var str = 'aaaaaaaaaaaabababbbbbbbbbbbbcccccccccccccccccdddd' var fir = 0, maxLen = 0 for(var i = 1; i < str.length; i++) { // console.log(str[i]) if(str[fir] != str[i]) { console.log(i-fir) fir = i } if((i+1) == str.length) { console.log((i+1)-fir) } } </script>
标签:fir,快慢,console,log,length,算法,str,var,指针 From: https://www.cnblogs.com/caijinghong/p/16915740.html