-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathASCIISubSequence.java
More file actions
40 lines (33 loc) · 1005 Bytes
/
ASCIISubSequence.java
File metadata and controls
40 lines (33 loc) · 1005 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
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.util.ArrayList;
public class ASCIISubSequence {
public static void main(String[] args) {
Ascii("", "abc");
System.out.println(AsciiArr("", "abc"));
}
//using void function
static void Ascii(String p,String up){
if(up.isEmpty()){
System.out.println(p);
return;
}
char ch=up.charAt(0);
Ascii(p+ch, up.substring(1));
Ascii(p, up.substring(1));
Ascii(p+(ch+0), up.substring(1));
}
//using ArrayList
static ArrayList<String> AsciiArr(String p,String up){
if(up.isEmpty()){
ArrayList<String> list=new ArrayList<>();
list.add(p);
return list;
}
char ch=up.charAt(0);
ArrayList<String> first= AsciiArr(p+ch, up.substring(1));
ArrayList<String> second= AsciiArr(p, up.substring(1));
ArrayList<String> third= AsciiArr(p+(ch+0), up.substring(1));
first.addAll(second);
first.addAll(third);
return first;
}
}