import java.util.*;

public class Solution {
    public ArrayList<ArrayList<Integer>> subsets(int[] S) { // 题目有点描述不明确,升序排列不具体,搞了半天在排序上!本来一个简单的回溯算法。
        
        Arrays.sort(S);
        LinkedList<Integer> ret = new LinkedList<>();
        doCombinationSum4(S, ret, 0);
        return ans;
    }
    ArrayList<ArrayList<Integer>> ans = new ArrayList<>();
     public void doCombinationSum4(int[] num, LinkedList<Integer> ret, int m) {
        ans.add(new ArrayList<>(ret));
        for (int i = m; i < num.length; i++) {
            ret.add(num[i]);
            doCombinationSum4(num, ret, i + 1);
            ret.removeLast();
        }
    }
}