Skip to content

Instantly share code, notes, and snippets.

@abantej
Last active March 21, 2018 04:10
Show Gist options
  • Save abantej/ac8a2231a8b8188da72c3122aaddc336 to your computer and use it in GitHub Desktop.
Save abantej/ac8a2231a8b8188da72c3122aaddc336 to your computer and use it in GitHub Desktop.

Is Unique

Implement an algorithm to determine if a string has all unique characters.

boolean isUniqueChars(String str) {
    if (str.length() > 128) return false;
    boolean[] char_set = new boolean[128];
    for (int i = 0; i < str.length(); i++) {
        int val = str.charAt(i);
        if (char_set[i]) {
            return false;
        }
        char_set[val] = true;
    }
    return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment