Ninety days: force buckle 830 questions, larger group position

Address: leetcode-cn.com/problems/po…

Double pointer, traversal once; But watch out for the special case of ‘AAA’

var largeGroupPositions = function(s) { let res = []; const n = s.length; for(let l1 = 0,l2 = 1; l2 < n; l2++) { if(s[l2] ! == s[l1] || l2 === n - 1) { if(l2 - l1 >= 3) { s[l2] === s[l1] ? res.push([l1, l2]) : res.push([l1, l2 - 1]); } else if(l2 - l1 === 2 && s[l2] === s[l1]) { res.push([l1, l2]); } l1 = l2; } } return res; };Copy the code

Execution time: 96 ms, beating 82.86% of all JavaScript commits

Memory consumption: 41.1 MB, beating 21.36% of all JavaScript commits