-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetsubsequence.java
More file actions
75 lines (54 loc) · 1.82 KB
/
Copy pathgetsubsequence.java
File metadata and controls
75 lines (54 loc) · 1.82 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import java.util.*;
public class getsubsequence {
public static void main(String[] args) {
//strings basics....
// Scanner sc = new Scanner(System.in);
// String str = "hello";
// System.out.println(str);
// for(int i =0 ; i<str.length(); i++){
// char ch= str.charAt(i); //character of the string...
// System.out.println(ch);
// }
// String ss= str.substring(1,3); //substring .......
// System.out.println(ss);
// //arraylist basics
// ArrayList<Integer> list= new ArrayList<>();
// list.add(10);
// list.add(20);
// list.add(30);
// list.add(40);
// System.out.println(list+"->"+list.size());
// for(int val:list){ //the way of printing arraylist by using the new type of loop ........
// System.out.println(val);
// }
// for(int i= 0; i<list.size();i++){
// int val=list.get(i); //other way of printng the arraylist......
// System.out.println(val);
// }
// list.set(2,300); // replacing the element of the arraylist/.......
// System.out.println(list+"->"+list.size());
// list.add(3,300000);
// System.out.println(list+"->"+list.size());
//getsubsequence question
Scanner sc = new Scanner(System.in);
String str = sc.next();
ArrayList<String> res = gss(str);
System.out.println(res);
}
public static ArrayList<String> gss(String str) {
if (str.length() == 0) {
ArrayList<String> bres = new ArrayList<>();
bres.add("");
return bres;
}
char ch = str.charAt(0);
String ros = str.substring(1);
ArrayList<String> rres = gss(ros);
ArrayList<String> mres = new ArrayList<>();
for (String rstr : rres) {
mres.add("" + rstr);
mres.add(ch + rstr);
}
return mres;
}
}