I have this solution which can pick the consecutive repeated elements (even if they are repeated itself too).
e.g., cases like:
{ 1, 4, 3, 6, 6, 8, 3, 3, 3, 3, 8, 9,
0 }; // Here 6 and 3 are repeated
{ 1, 4, 3, 3, 6, 6, 8, 3, 3, 3, 3, 8,
9, 0 }; // Here 6 repeated once and 3
repeated twice
Sample Code:
int[] myList = new int[] { 1, 4, 3, 3, 6, 6, 8, 3, 3, 3, 3, 8, 9, 0 };
Dictionary<int, List<int>> groupDict = new Dictionary<int, List<int>>();
string characters = string.Join("", myList.ToArray());
for (int i = 0; i < characters.Length; i++)
{
int cInt = int.Parse(characters*.ToString());*
MatchCollection mColl = Regex.Matches(characters.Substring(i), “^” + characters + “{2,}”);
if (mColl.Count > 0)
{
if (!groupDict.Keys.Contains(cInt))
{
groupDict.Add(cInt, new List());
}
groupDict[cInt].Add(mColl[0].Length);
i += mColl[0].Length - 1;
}
}
}
For first case it will show you: (in-memory result)
6 → 2
3 → 4
For second case it will show you: (in-memory result)
6 → 2
3 → 2, 4
Hope it is useful for you.