# Subsets

## Problem

Given a set of distinct integers, S, return all possible subsets.

Note: Elements in a subset must be in non-descending order.

The solution set must not contain duplicate subsets.

## Example

If S = [1,2,3], a solution is:

[
[3],
[1],
[2],
[1,2,3],
[1,3],
[2,3],
[1,2],
[]
]

## Key Point

** Elements in a subset must be in non-descending order.**

## Code - Java

class Solution {
/**
* @param S: A set of numbers.
* @return: A list of lists. All valid subsets.
*/
public ArrayList<ArrayList<Integer>> subsets(int[] nums) {
ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();

Arrays.sort(nums);
for (int i = 0; i < nums.length; i++) {
ArrayList<ArrayList<Integer>> newResult = new ArrayList<>(result);
for (ArrayList<Integer> list : result) {
ArrayList<Integer> newList = new ArrayList<Integer>(list);
}
result = newResult;
}
return result;
}
}

public class Solution {
private List<List<Integer>> assemble(int[] S, int n, boolean included) {
if (n == S.length - 1) {
List<List<Integer>> result = new ArrayList<List<Integer>>();
if (included) {
return result;
} else {
List<Integer> list = new ArrayList<Integer>();
return result;
}
}
List<List<Integer>> result = new ArrayList<List<Integer>>();
for (List<Integer> l : assemble(S, n + 1, true)) {
List<Integer> list = new ArrayList<Integer>();
if (included) {
}
}
for (List<Integer> l : assemble(S, n + 1, false)) {
List<Integer> list = new ArrayList<Integer>();
if (included) {
}
}
return result;
}

public List<List<Integer>> subsets(int[] S) {
List<List<Integer>> result = new ArrayList<List<Integer>>();