forked from dimpeshmalviya/JavaBasicPrograms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdupli_remove_recc.java
More file actions
24 lines (24 loc) · 834 Bytes
/
dupli_remove_recc.java
File metadata and controls
24 lines (24 loc) · 834 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
public class dupli_remove_recc {
//code to remove duplicates using recursion.
public static void removeDuplicates(String str, int idx, StringBuilder newStr, boolean map[]){
//base case
if(idx == str.length()){
System.out.println(newStr);
return;
}
//kaam
char currChar = str.charAt(idx);
if(map[currChar-'a'] ==true){
//then it is duplicate char
//calling of next index
removeDuplicates(str, idx+1, newStr, map);
}else{
map[currChar-'a']=true;
removeDuplicates(str, idx+1, newStr.append(currChar), map);
}
}
public static void main(String[] args) {
String str= "appnnacolleege";
removeDuplicates(str, 0, new StringBuilder(""), new boolean[26]);
}
}