Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@thmain
Created October 15, 2017 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/3810ca3ad979fc384781851e8c56cbd1 to your computer and use it in GitHub Desktop.
Save thmain/3810ca3ad979fc384781851e8c56cbd1 to your computer and use it in GitHub Desktop.
public class RemoveDuplicates {
public static String removeDuplicates(String s){
char[] chrArr = s.toCharArray();
boolean[] asciiChrSet = new boolean[256];
StringBuilder stb = new StringBuilder();
for(int i=0;i<chrArr.length;i++){
if(asciiChrSet[chrArr[i]]){
continue;
}
asciiChrSet[chrArr[i]] = true;
stb.append(chrArr[i]);
}
return stb.toString();
}
public static void main(String[] args) {
String s = "tutorialhorizon";
System.out.println(removeDuplicates(s));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment