I am trying to remove every character repeated over 2 times from an extremely long string. So, for example, the word Terrrrrrific
becomes Terrific
.
Now my question is, how do I filter out repeats that include more than a single character the same way, i.e. if I have Words words words words words
I want to filter it down to words words
, however, it might be something less sensible, such as abcdabcdabcdabcdabcd
which should become abcdabcd
.
I do suspect that I should use a suffix tree, but I'm not sure how to go at the algorithm exactly.