-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathg_subseq_loop.java
More file actions
35 lines (30 loc) · 1.09 KB
/
Copy pathg_subseq_loop.java
File metadata and controls
35 lines (30 loc) · 1.09 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
import java.util.ArrayList;
public class g_subseq_loop {
static ArrayList<String> solution(String str) {
ArrayList<String> list = new ArrayList<>();
for(int i = 0; i < str.length(); i++) {
char currentChar = str.charAt(i);
if(list.size() == 0) {
list.add("");
// "" + currentChar - because currentChar data type is char
// and our list can store only String type of data
// so after concatenation it will become String type of daya
list.add("" + currentChar);
continue;
}
int n = list.size();
for(int j = 0; j < n; j++) {
String temp = list.get(j) + currentChar;
if(!list.contains(temp)) {
list.add(temp);
}
}
}
return list;
}
public static void main(String[] args) {
String str = "ravi";
ArrayList<String> output = solution(str);
System.out.println(output);
}
}