Skip to content

Instantly share code, notes, and snippets.

@reza-ryte-club
Last active August 29, 2015 14:27
Show Gist options
  • Save reza-ryte-club/8ea0e79c40b1b7f481b1 to your computer and use it in GitHub Desktop.
Save reza-ryte-club/8ea0e79c40b1b7f481b1 to your computer and use it in GitHub Desktop.
Check whether a string has uniqe characters
package com.company;
public class Unique {
public static boolean checkUnique(String word){
if(word.length()>256) return false;// if a string is more than 256 characters long, it repeats any of the string
boolean[] charset = new boolean[256];
for(int i = 0;i<word.length();i++){
char c = word.charAt(i);
if(charset[c]) return false;
charset[c]=true;
}
return true;
}
public static void main(String[] args) {
System.out.println(checkUnique("Helow"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment