-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubseq2.java
More file actions
30 lines (25 loc) · 783 Bytes
/
Copy pathsubseq2.java
File metadata and controls
30 lines (25 loc) · 783 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.HashSet;
public class subseq2 {
public static void subsquence(String str ,int idx, HashSet<String> set ,String newStr ){
if(idx==str.length()){
if(set.contains(newStr)){
return ;
}
else{
set.add(newStr);
char currChar = str.charAt(idx);
// to be syso
subsquence(str, idx+1, set, newStr+currChar);
// not to be
subsquence(str, idx+1, set, newStr);
System.out.println(newStr);
}
return ;
}
}
public static void main(String[] args) {
HashSet<String> set = new HashSet<>();
String str= "abbbbdc";
subsquence(str,0,set,"");
}
}