Last active
August 29, 2015 14:02
-
-
Save WOLOHAHA/1408fb20ad4eaad7447a to your computer and use it in GitHub Desktop.
Implement an algorithm to determine if a string has all unique characters. Whatif you cannot use additional data structures?
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 uniqueChar(String s) { | |
if (s == null) | |
throw new IllegalArgumentException(); | |
if (s.length() <= 1) | |
return true; | |
if (s.length() > 256) | |
return false; | |
boolean[] iFlag = new boolean[256]; | |
for (int i = 0; i < s.length(); i++) { | |
if (iFlag[s.charAt(i)]) { | |
return false; | |
} | |
iFlag[s.charAt(i)] = true; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment