Skip to content

Instantly share code, notes, and snippets.

Created June 15, 2014 16:12
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/071cbca01a61d0fb3e9a to your computer and use it in GitHub Desktop.
Save anonymous/071cbca01a61d0fb3e9a to your computer and use it in GitHub Desktop.
class Solution{
/*
* Time complexity O(n); Space complexity O(1).
*/
public boolean isAllUniqChar(String str){
if(str == null) return false; // Make sure that the string is valid.
boolean[] temp = new boolean[128]; // Temp stores all 128 ASCII characters' presences in the string.
char[] chars = str.toCharArray(); // Convert the string into Char array so that we can iterate each character.
for(boolean i in:temp) i = false; // Initialize the temp array.
for(char c in:chars){
int index = c; // Get the ASCII value of a char.
if(!temp[index]) temp[index] = true; // Check if this char has showed up before. If not, mark its presence then proceed.
else return false; // If this char has showed up once, then this string has duplicate chars.
}
return true; // All chars are unique.
}
}
@ruijianw
Copy link

Can I comment this?

@monkerek
Copy link

额。。

@LogicMonsters
Copy link

cool

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