Java: determine if a String has all unique characters

preview_player
Показать описание

"Implement and algorithm to determine if a String has all unique characters" - a question from cracking the coding interview.
Рекомендации по теме
Комментарии
Автор

i would probably suggest this as a first solution bc it probably account lowercase a and uppercase A as the same. to do this, I would implement something that checks ascii value

free-palestine
Автор

Hi Aron, thank you for this video. The solution doesn't ignore upper or lower cases of the string. For example, if the string is "Ankita", it returns true. Hence if we either convert a character to an upper or lower case, this error can be avoided.
public static boolean hasUniqueCharacters(String s) {
Set<Character> set = new HashSet<>();
for(char ch: s.toCharArray()){

return false;
set.add(ch);
}
return true;
}

ankitapatil
Автор

I keep using hashsets on every problem. That is like my greatest backup and I feel dumb spamming it on every coding problem haha.

mcreyfonacier
join shbcf.ru