JavaScript Solution - DFS Approach?
I am not sure if this is a good way of doing it, but I thought I would post and get your guys\' opinions. Thank you.\n\n\nvar minReorder = function(n, connectio
I am not sure if this is a good way of doing it, but I thought I would post and get your guys\' opinions. Thank you.\n\n```\nvar minReorder = function(n, connections) {\n    const graph = [];\n    const set = new Set();\n    \n    for (let i = 0; i < n; i++) {\n        graph[i] = [];\n    }\n    \n    for (const [u, v] of connections) {\n        graph[u].push(v);\n        graph[v].push(u);\n        set.add(`${u}#${v}`);\n    }\n    \n    let count = 0;\n    \n    dfs(0, -1)\n    \n    return count;\n    \n    \n    function dfs(node, parent) {\n        \n        if (set.has(`${parent}#${node}`)) count++;\n        \n        for (const nei of graph[node]) {\n            if (nei === parent) continue;\n       \n            dfs(nei, node);\n        }\n    }\n}; \n```
['Depth-First Search', 'JavaScript']