Skip to content

Instantly share code, notes, and snippets.

Created June 16, 2014 02:55
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 anonymous/6b88e0640729b97e460b to your computer and use it in GitHub Desktop.
Save anonymous/6b88e0640729b97e460b to your computer and use it in GitHub Desktop.
public boolean isUnique(String line) {
int[] count = new int[256];
for(int i = 0; i < line.length(); i++)
count[line.charAt(i)]++;
for(int i = 0; i < 256; i++) {
if(count[i] > 1)
return false;
}
return true;
}
@jason51122
Copy link

  1. There are 2 for loops in your program. You can use only one to achieve the same goal.
  2. You did not check the edge case when input is null.
  3. You should return the result directly if the length of string is 0 or bigger than 256.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment