Implicit Graph DFS
Implicit Graph DFS Implicit Graph DFS Combinations(组合) 需要注意的是以下几点: 空值 :看清题目,如果当 nums 的个数为 0 的时候,需要不需要加入空列,如果需要就不能在判断空条件下加入 .length 排序 :在做组合类题目之前一定要确定这个 nums 是个有序的数组,如果不是就需要排序 dfs() :一般都是 dfs(collection, [condition], index, level result, final results) 添加result到results中 :如果没有特殊条件直接添加,否则在特殊条件下 加入 并 返回 return for循环 :注意 i 的初始值是 index for循环体 :dfs老套路,加入,再 dfs ,再删去,dfs时,注意 [condition] 是否需要改变, index 传的是和 i 相关的,如果不可以重复传入 i + 1 ,如果可以重复传入 i SubSets(最简单的Combination) public class Solution { public List<List<Integer>> subsets(int[] nums) { List<List<Integer>> results = new ArrayList<>(); if (nums == null) { return results; } // 一定要排个序之后再做 Arrays.sort(nums); dfs(nums, 0, new ArrayList<Integer>(), results); return results; } private void dfs(int[] nums, int index, List<Integer> result, List...