@@ -0,0 +1,968 @@
+package cracking_the_coding_interview.arrays_and_strings;%0A%0Aimport java.util.HashSet;%0A%0A/*%0A%09This class implements a method to check if all characters contained in a string are unique.%0A*/%0A%0Aclass UniqueChars%7B%0A%0A%0A%09// Checks if all characters contained in string s are unique%0A%09// Time Complexity: O(N)%09%09N - No. of characters in string s%09%0A%09// Space Complexity: O(N)%09%0A%0A%09public static boolean check(String s)%7B%0A%0A%0A%09%09// throw exception if string is empty%0A%09%09if(s == null)%7B%0A%09%09%09throw new NullPointerException(%22String is empty%22);%0A%09%09%7D%0A%0A%09%09// Create hashset to hold all characters%0A%09%09HashSet%3CCharacter%3E chars = new HashSet%3CCharacter%3E(s.length());%0A%0A%09%09// For each character in s%0A%09%09for(int i=0;i%3Cs.length();i++)%7B%0A%0A%09%09%09// If it is already present in chars, return false%0A%09%09%09if(chars.contains(s.charAt(i)))%7B%0A%09%09%09%09return false;%0A%09%09%09%7D%09%0A%09%09%09else %7B // otherwise, add this character to chars%0A%09%09%09%09chars.add(s.charAt(i));%0A%09%09%09%7D%0A%0A%09%09%7D%09%0A%0A%09%09// if no character was found twice, return true%0A%09%09return true;%0A%09%7D%0A%0A%0A%7D%0A

Add class to check whether all characters in a string are unique