-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxyz.java
43 lines (40 loc) · 1.21 KB
/
xyz.java
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.util.ArrayList;
import java.util.Arrays;
public class xyz {
public static void main(String[] args) {
String st = "abc";
// System.out.println(skipCharacter(st));
System.out.println(subString(st,""));
}
static String skipCharacter(String st, String ans){
if(st.isEmpty()){
return ans;
}
if(st.charAt(0) != 'a'){
return skipCharacter(st.substring(1), ans+st.charAt(0));
}else{
return skipCharacter(st.substring(1),ans);
}
}
static String skipCharacter(String st){
if(st.isEmpty()){
return "";
}
if(st.charAt(0) != 'a'){
return st.charAt(0) + skipCharacter(st.substring(1));
}else{
return skipCharacter(st.substring(1));
}
}
static ArrayList<String> subString(String st, String ans){
if(st.isEmpty()){
ArrayList<String> arr = new ArrayList<>();
arr.add(ans);
return arr;
}
ArrayList<String> arrL = subString(st.substring(1), ans + st.charAt(0));
ArrayList<String> arrR = subString(st.substring(1) , ans);
arrL.addAll(arrR);
return arrL;
}
}