@Test public void basicTest3() { List<Integer>[] gra = new List[0]; Assert.assertEquals("[]", EulerCycle.solveUndirectGraph(gra).toString()); }
public static List<Integer> solveUndirectGraph(List<Integer>[] graph) { List<Integer> res = new ArrayList<>(); for (List<Integer> edge : graph) { if (edge.size() % 2 == 1) { return res; } } for (List<Integer> i : graph) { Collections.sort(i); } int n = graph.length; if (n == 0) return res; Set<Integer>[] seen = new Set[n]; for (int i = 0; i < n; i++) { seen[i] = new HashSet<>(); } LinkedList<Integer> path = new LinkedList<>(); dfs(0, graph, seen, path); return path; }
EulerCycle { public static List<Integer> solveUndirectGraph(List<Integer>[] graph) { List<Integer> res = new ArrayList<>(); for (List<Integer> edge : graph) { if (edge.size() % 2 == 1) { return res; } } for (List<Integer> i : graph) { Collections.sort(i); } int n = graph.length; if (n == 0) return res; Set<Integer>[] seen = new Set[n]; for (int i = 0; i < n; i++) { seen[i] = new HashSet<>(); } LinkedList<Integer> path = new LinkedList<>(); dfs(0, graph, seen, path); return path; } }
EulerCycle { public static List<Integer> solveUndirectGraph(List<Integer>[] graph) { List<Integer> res = new ArrayList<>(); for (List<Integer> edge : graph) { if (edge.size() % 2 == 1) { return res; } } for (List<Integer> i : graph) { Collections.sort(i); } int n = graph.length; if (n == 0) return res; Set<Integer>[] seen = new Set[n]; for (int i = 0; i < n; i++) { seen[i] = new HashSet<>(); } LinkedList<Integer> path = new LinkedList<>(); dfs(0, graph, seen, path); return path; }  }
EulerCycle { public static List<Integer> solveUndirectGraph(List<Integer>[] graph) { List<Integer> res = new ArrayList<>(); for (List<Integer> edge : graph) { if (edge.size() % 2 == 1) { return res; } } for (List<Integer> i : graph) { Collections.sort(i); } int n = graph.length; if (n == 0) return res; Set<Integer>[] seen = new Set[n]; for (int i = 0; i < n; i++) { seen[i] = new HashSet<>(); } LinkedList<Integer> path = new LinkedList<>(); dfs(0, graph, seen, path); return path; }  static List<Integer> solveUndirectGraph(List<Integer>[] graph); }
EulerCycle { public static List<Integer> solveUndirectGraph(List<Integer>[] graph) { List<Integer> res = new ArrayList<>(); for (List<Integer> edge : graph) { if (edge.size() % 2 == 1) { return res; } } for (List<Integer> i : graph) { Collections.sort(i); } int n = graph.length; if (n == 0) return res; Set<Integer>[] seen = new Set[n]; for (int i = 0; i < n; i++) { seen[i] = new HashSet<>(); } LinkedList<Integer> path = new LinkedList<>(); dfs(0, graph, seen, path); return path; }  static List<Integer> solveUndirectGraph(List<Integer>[] graph);  }