I am working through the book \"Cracking the Coding Interview\" and I have come across questions here asking for answers, but I need help comparing my answer to the solution
As referenced from 'Cracking the Coding Interview', an alternative solution exists:
boolean isUniqueChars(String str) {
if(str.length() > 128) return false;
boolean[] char_set = new boolean[128];
for(int i = 0; i < str.length(); i++) {
int val = str.charAt(i);
if(char_set[val]) {
return false;
}
char_set[val] = true;
}
return true;
}
Of course, to achieve better space complexity, please refer to the above example by @templatetypedef