public List<List<Integer>> subsets(int[] nums) { List<List<Integer>> res = new ArrayList<>(); //Arrays.sort(nums); 不重复没必要sort backtrack(res, new ArrayList<>(), nums, 0); return res; }
privatevoidbacktrack(List<List<Integer>> list , List<Integer> tempList, int [] nums, int start){ list.add(new ArrayList<>(tempList)); for(int i = start; i < nums.length; i++){ tempList.add(nums[i]); backtrack(list, tempList, nums, i + 1); tempList.remove(tempList.size() - 1); } }