Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4
Use a map where keys are characters and values are number of appearances. Initiate the map entries with 0 on all characters. Then increase the value of the entry with the current character as a key while iterating through the characters.
14th May 2022, 5:48 PM
Mustafa A
Mustafa A - avatar
14th May 2022, 5:43 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Define an int or char array, size 256, that represents 256 possible values of a byte. Loop through the characters of the string, using the byte value of each character as an index into the array. If the array value is zero then increment the corresponding element. Else, you found a duplicate. You may break out of the loop and report it.
15th May 2022, 10:58 AM
Brian
Brian - avatar