-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram67.java
More file actions
27 lines (22 loc) · 773 Bytes
/
Program67.java
File metadata and controls
27 lines (22 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public class Program67 {
public static boolean[] map = new boolean[26];
//Remove Duplicates from a String : "abbccda"
public static void removeDuplicates(String str, int idx, String newString) {
if (idx == str.length()) {
System.out.println(newString);
return;
}
char currChar = str.charAt(idx);
if (map[currChar - 'a'] == true) {
removeDuplicates(str, idx + 1, newString);
} else {
newString += currChar;
map[currChar - 'a'] = true;
removeDuplicates(str, idx + 1, newString);
}
}
public static void main(String[] args) {
String str = "abbccda";
removeDuplicates(str, 0, " ");
}
}