Corrected

The previous solution didn't work for string containing duplicated repetitions. Eg. abaaabaa
Merge pull request #45 from filannim/patch-3

Corrected