mr_eclair mr_eclair - 23 days ago 5
C Question

determine if a string has all unique characters?

Can anybody tell me how to implement a program to check a string contains all unique chars ?

Answer

If you are talking about an ASCII string:

  1. Create an int array [0-255], one for each character index, initialised to zero.

  2. Loop through each character in the string and increment the respective array position for that character

  3. If the array position already contains a 1, then that character has already been encountered. Result => Not unique.

  4. If you reach the end of the string with no occurrence of (3), Result => the string is unique.