-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindSubsets.java
More file actions
35 lines (25 loc) · 862 Bytes
/
FindSubsets.java
File metadata and controls
35 lines (25 loc) · 862 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
31
32
33
34
35
import java.util.*;
public class FindSubsets {
List<List<Integer>> output= new ArrayList<>();
public List<List<Integer>> findSubsets(int[] arr){
int n= arr.length;
helper(0, new ArrayList<>(), arr);
return output;
}
public void helper(int first, ArrayList<Integer> curr, int[] arr){
if(first == arr.length){
output.add(new ArrayList<>(curr));
return;
}
helper(first+1, curr, arr);
curr.add(arr[first]);
helper(first+1, curr, arr);
curr.remove(curr.size() -1);
}
public static void main(String[] args) {
FindSubsets obj= new FindSubsets();
int[] arr= {1,2,3};
List<List<Integer>> result= obj.findSubsets(arr);
System.out.println(result);
}
}