Given a set of distinct integers, nums, return all possible subsets (the power set).
Note: The solution set must not contain duplicate subsets.
Example:
Input: nums = [1,2,3]
Output:
[
[3],
[1],
[2],
[1,2,3],
[1,3],
[2,3],
[1,2],
[]
]
classSolution {publicList<List<Integer>> subsets(int[] nums) {List<List<Integer>> result =newArrayList<List<Integer>>();if (nums ==null||nums.length==0) return result;// dfsList<Integer> list =newArrayList<Integer>();dfs(nums,0, list, result);return result; }privatevoiddfs(int[] nums,int pos,List<Integer> list,List<List<Integer>> ret) {// Put it first, let's make it have an empty setret.add(newArrayList<Integer>(list));for (int i = pos; i <nums.length; i++) {list.add(nums[i]);dfs(nums, i +1, list, ret);list.remove(list.size() -1); } }}