Is it possible to remove duplicate characters from a string without saving each character you’ve seen in an array and checking to see if new characters are already in that array? That seems highly inefficient. Surely there must be a quicker method?
Is it possible to remove duplicate characters from a string without saving each character
Share
You can use a boolean array indexed by character:
For byte-sized ASCII-like characters, the above would be appropriate. For 16-bit Unicode:
and so on. Then, for each character in the string it’s a simple lookup to see whether that boolean has already been set.