Created
February 10, 2013 01:47
-
-
Save silverjam/4747958 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import java.util.*; | |
public class HasUniqueChars | |
{ | |
public static boolean hasUniqueChars(String toTest) | |
{ | |
char charArray[] = toTest.toCharArray(); | |
Arrays.sort(charArray); | |
for (int x = 1; x < charArray.length; x++) | |
{ | |
if ( charArray[x] == charArray[x-1] ) | |
return false; | |
} | |
return true; | |
} | |
public static void main(String args[]) | |
{ | |
String testData[] = { | |
"abc", | |
"abcc", | |
"abcdefhi", | |
"abcdefhiabcdefhi", | |
"ccc", | |
"xxxkjsdfkjqqqdkjfd", | |
"abcdefghijklmnopqrstuvwxyz", | |
}; | |
for (String test : testData) | |
{ | |
if ( hasUniqueChars(test) ) | |
{ | |
System.out.println(" hasUniqueChars(\"" + test + "\")"); | |
} | |
else | |
{ | |
System.out.println("! hasUniqueChars(\"" + test + "\")"); | |
} | |
} | |
} | |
} | |
// vim: sw=4:ts=4:sts=4:et:ai: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment