I came across the following question in Cracking the Coding Interview, 1.1:
Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures?
Here is my solution:
public boolean allUnique(String input) {
HashSet<Character> set = new Hashset<Character>();
char c;
for (int i = 0; i < input.length(); i++) {
c = input.charAt(i);
if (set.contains(c)) return false;
set.add(c);
}
return true;
Does my solution work, and how efficient is it? I was also wondering if someone could explain ASCII and how it is relevant to this problem, since it was briefly mentioned in the book's solution. Is this why we are able to type-cast each char in the String to an integer?
Thank you!