Skip to content

Instantly share code, notes, and snippets.

@zhensongren
Created April 3, 2015 19:48
Show Gist options
  • Save zhensongren/4c576de94989fb4ddc9e to your computer and use it in GitHub Desktop.
Save zhensongren/4c576de94989fb4ddc9e to your computer and use it in GitHub Desktop.
CareerCup 1.1
//test if a string is consist of a sequence of all unique characters
public class UniqueChar {
public static boolean isUnique(String x) {
if (x.length() > 256)
return false;
boolean[] b = new boolean[256];
for(int i=0; i<x.length(); i++) {
int value = x.charAt(i);
if (b[value])
return false;
b[value] = true;
}
return true;
}
public static void main (String[] args) {
String s = args[0];
System.out.println(isUnique(s));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment