File tree 1 file changed +9
-9
lines changed
scripts/algorithms/I/Increasing Subsequences
1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change
1
+ // Runtime: 48 ms (Top 13.29%) | Memory: 68.6 MB (Top 66.07%)
1
2
class Solution {
2
3
HashSet <List <Integer >> set ;
3
4
public List <List <Integer >> findSubsequences (int [] nums ) {
4
5
set =new HashSet <>();
5
-
6
+
6
7
dfs (nums ,0 ,new ArrayList <>());
7
-
8
-
8
+
9
9
List <List <Integer >> ans =new ArrayList <>();
10
10
if (set .size ()>0 ){
11
11
ans .addAll (set );
12
12
}
13
13
return ans ;
14
14
}
15
-
15
+
16
16
private void dfs (int nums [], int start , List <Integer > temp ){
17
17
if (start ==nums .length ) return ;
18
-
18
+
19
19
for (int i =start ;i <nums .length ;i ++){
20
20
if (temp .size ()==0 || temp .get (temp .size ()-1 )<=nums [i ]){
21
21
temp .add (nums [i ]);
22
-
22
+
23
23
if (temp .size ()>=2 ) set .add (new ArrayList <>(temp ));
24
-
24
+
25
25
dfs (nums ,i +1 ,temp );
26
- temp .remove (temp .size ()-1 );
26
+ temp .remove (temp .size ()-1 );
27
27
}
28
28
}
29
29
}
30
- }
30
+ }
You can’t perform that action at this time.
0 commit comments