I like Bill's solution using Split to find the repeats-- that's clever. Here is a pattern matching approach
In[1]:= ff[{z : Longest[PatternSequence[Repeated[x_, {2, Infinity}]]],
y___}] := {Range[x - Length[{z}] + 1, x] /. List -> Sequence, y}
In[2]:= ff[{x_}] := {x}
In[3]:= Map[ff, {{2, 2, 7}, {2, 2, 3, 7}, {3}, {6, 6, 6, 7}}]
Out[3]= {{1, 2, 7}, {1, 2, 3, 7}, {3}, {4, 5, 6, 7}}
I made a function that matches a pattern of a repeated sequence, named z, of repeating elements, named x, and the rest of the elements, named y and then reconstructed your list. If you give it a long list it appears to be faster than using split but I am not sure exactly why.
In[9]:= data =
Flatten[Table[{{2, 2, 7}, {2, 2, 3, 7}, {3}, {6, 6, 6, 7}}, 10000],
1];
In[10]:= Map[ff, data]; // AbsoluteTiming
Out[10]= {0.144403, Null}
In[11]:= Map[g, data]; // AbsoluteTiming
Out[11]= {0.246992, Null}
Regards,
Neil