Last active
August 29, 2015 14:17
-
-
Save hanaori/6ca661a977e53885f7d8 to your computer and use it in GitHub Desktop.
Check the String whether it has the same character.
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 str) { | |
boolean isUnique = true; | |
HashSet<Character> hs = new HashSet<>(); | |
for(char c: str.toCharArray()){ | |
if(!hs.contains(c)){ | |
hs.add(c); | |
}else{ | |
isUnique = false; | |
break; | |
} | |
} | |
return isUnique; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment