Code Golf: Duplicate Character Removal in String
Posted
by
Alex
on Stack Overflow
See other posts from Stack Overflow
or by Alex
Published on 2009-08-27T23:57:50Z
Indexed on
2011/01/10
12:53 UTC
Read the original article
Hit count: 217
code-golf
The challenge: The shortest code, by character count, that detects and removes duplicate characters in a String. Removal includes ALL instances of the duplicated character (so if you find 3 n's, all three have to go), and original character order needs to be preserved.
Example Input 1:
nbHHkRvrXbvknExample Output 1:
RrX
Example Input 2:
nbHHkRbvnrXbvknExample Output 2:
RrX
(the second example removes letters that occur three times; some solutions have failed to account for this)
(This is based on my other question where I needed the fastest way to do this in C#, but I think it makes good Code Golf across languages.)
© Stack Overflow or respective owner