-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathSubSequenceOfString.java
More file actions
30 lines (28 loc) · 987 Bytes
/
SubSequenceOfString.java
File metadata and controls
30 lines (28 loc) · 987 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
import java.util.ArrayList;
class SubSequenceOfString{
public static void main(String[] args) {
String str = "abcd";
ArrayList<String> subSeq = new ArrayList<>();
for(int i = 0; i<str.length(); i++){
char firstChar = str.charAt(i);
if(subSeq.size()==0){
subSeq.add(""); // Not Include it
subSeq.add(String.valueOf(firstChar)); // Include It
continue;
}
int len = subSeq.size();
for(int j = 0; j<len; j++){
// Not Include it
String temp2 = ""+firstChar;
if(!subSeq.contains(temp2)){
subSeq.add(temp2); // Include it
}
String temp = subSeq.get(j)+firstChar;
if(!subSeq.contains(temp)){
subSeq.add(temp); // Include it
}
}
}
System.out.println("Sub Seq "+subSeq);
}
}