Skip to content

Instantly share code, notes, and snippets.

@JoyceeLee
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoyceeLee/8118612ec2b571730f30 to your computer and use it in GitHub Desktop.
Save JoyceeLee/8118612ec2b571730f30 to your computer and use it in GitHub Desktop.
/* 1.1 Implement an algorithm to determine if a string has all unique characters. Whatif you cannot use additional data structures? */
public class uniqueChar {
public boolean allUnique(String s) {
if(s==null || s.length()==0) return true;
boolean[] appear = new boolean[256];
for(int i=0; i<s.length(); i++) {
if(appear[s.charAt(i)]) return false;
appear[s.charAt(i)] = true;
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment