MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / depthFirstSearch

Method depthFirstSearch

java/0261-graph-valid-tree.java:26–42  ·  view source on GitHub ↗
(
        int node,
        int previous,
        Set<Integer> visited
    )

Source from the content-addressed store, hash-verified

24 }
25
26 private boolean depthFirstSearch(
27 int node,
28 int previous,
29 Set<Integer> visited
30 ) {
31 if (visited.contains(node)) return false;
32
33 visited.add(node);
34
35 for (var neighbor : adjacencyList.get(node)) {
36 if (neighbor == previous) continue;
37
38 if (!depthFirstSearch(neighbor, node, visited)) return false;
39 }
40
41 return true;
42 }
43}

Callers 1

validTreeMethod · 0.95

Calls 3

containsMethod · 0.45
addMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected