public class Solution { public IList<IList<int>> LargeGroupPositions(string S) { //"babaaaabbb" var list = new List<IList<int>>(); int len = S.Length; if (len > 0) { var last = S[0]; var begin = 0; var end = S.Length - 1; for (int i = 0; i < len; i++) { var cur = S[i]; if (last != cur) { end = i - 1; var dif = end - begin + 1; if (dif >= 3) { var poslist = new List<int>(); poslist.Add(begin); poslist.Add(end); list.Add(poslist); } last = S[i]; begin = i; } end = i; } if (end - begin >= 2) { var list3 = new List<int>(); list3.Add(begin); list3.Add(end); list.Add(list3); } } return list; } }