Created
October 15, 2017 16:47
-
-
Save thmain/3810ca3ad979fc384781851e8c56cbd1 to your computer and use it in GitHub Desktop.
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 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