-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSolution491.java
More file actions
executable file
·38 lines (32 loc) · 1.09 KB
/
Solution491.java
File metadata and controls
executable file
·38 lines (32 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
36
37
38
import java.util.*;
/**
* Created by slade on 2019/6/28.
*/
public class Solution491 {
List<List<Integer>> ans = new ArrayList<>();
List<Integer> init = new ArrayList<>();
HashSet<String> hashSet = new HashSet<>();
public List<List<Integer>> findSubsequences(int[] nums) {
Subsquences(nums, init);
return ans;
}
void Subsquences(int[] nums, List<Integer> tmp) {
if (tmp.size() > 1 && !hashSet.contains(tmp.toString())) {
ans.add(tmp);
hashSet.add(tmp.toString());
}
for (int i = 0; i < nums.length; i++) {
if (tmp.size() == 0 || tmp.get(tmp.size() - 1) <= nums[i]) {
int[] nextNums = Arrays.copyOfRange(nums, i + 1, nums.length);
List<Integer> nextTmp = new ArrayList<>(tmp);
nextTmp.add(nums[i]);
Subsquences(nextNums, nextTmp);
}
}
}
public static void main(String[] args) {
Solution491 s = new Solution491();
int[] nums = {4, 6, 7, 7};
System.out.println(s.findSubsequences(nums));
}
}