Skip to content

Instantly share code, notes, and snippets.

@youchen
Last active August 29, 2015 14:02
Show Gist options
  • Save youchen/1596073837940c97a098 to your computer and use it in GitHub Desktop.
Save youchen/1596073837940c97a098 to your computer and use it in GitHub Desktop.
cc150 - 1.1 UniqueCharChecker
package cc150;
import java.util.*;
public class _01_01 {
public static void main(String[] args) {
System.out.println(_01_01.allCharUnique("abcdefghijklmnopqrstuvwxyz!@#$%^&*()"));
System.out.println(_01_01.allCharUnique("abcdefghii"));
System.out.println(_01_01.allCharUnique("!@"));
}
public static boolean allCharUnique(String str){
Hashtable<Integer, Character> charMap = new Hashtable<Integer, Character>(str.length());
charMap.put(0, str.charAt(0));
for(int i = 1; i < str.length(); i++){
if (charMap.containsValue(str.charAt(i) ) ) {
return false;
}
charMap.put(i, str.charAt(i));//add(i, str.charAt(i));
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment