Created
June 16, 2014 02:55
-
-
Save anonymous/6b88e0640729b97e460b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
commented
Jun 16, 2014
- There are 2 for loops in your program. You can use only one to achieve the same goal.
- You did not check the edge case when input is null.
- 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