We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents fabe425 + f2dd5e3 commit 3e90f97Copy full SHA for 3e90f97
solutions/java/RemoveDuplicatesFromString.java
@@ -0,0 +1,20 @@
1
+public class RemoveDuplicatesFromString {
2
+ public static void main(String[] args) {
3
+ RemoveDuplicatesFromString rsd = new RemoveDuplicatesFromString();
4
+ String input = "Tree Traversal";
5
+ System.out.println(rsd.getUniqueString(input));
6
+ }
7
+
8
+ public String getUniqueString(String input) {
9
+ boolean[] isUsed = new boolean[256];
10
+ StringBuffer sb = new StringBuffer();
11
+ for (int i = 0; i < input.length(); i++) {
12
+ int position = input.charAt(i);
13
+ if (!isUsed[position]) {
14
+ sb.append(input.charAt(i));
15
+ isUsed[position] = true;
16
17
18
+ return sb.toString();
19
20
+}
0 commit comments