样例
输入
{1,8,5,4}
输出
[[], [1], [1, 4], [1, 4, 5], [1, 4, 5, 8], [1, 4, 8], [1, 5], [1, 5, 8], [1, 8], [4], [4, 5], [4, 5, 8], [4, 8], [5], [5, 8], [8]]
public List<List<Integer>> allSubList(int[] arr){
List<Integer> temp = new ArrayList<>();
List<List<Integer>> result = new ArrayList<>();
Arrays.sort(arr);
group(arr, temp, result, 0);
return result;
}
private void group(int[] arr, List<Integer> temp, List<List<Integer>> result, int index){
result.add(new ArrayList<>(temp));
if (temp.size() == arr.length)
return;
for(int i = index; i < arr.length; i++){
temp.add(arr[i]);
group(arr, temp, result,i+1);
temp.remove(temp.size()-1);
}
}
标签:arr,group,temp,int,List,子集,result,数组 From: https://www.cnblogs.com/MarkLeeBYR/p/16801247.html