𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 | 𝗦𝗶𝗺𝗽𝗹𝗲 𝗩𝗶𝗱𝗲𝗼 𝗦𝗼𝗹𝘂𝘁𝗶𝗼𝗻 | DFS | Detailed Explanation
Intuition & Approach\n Describe your approach to solving the problem. \n\uD835\uDDD7\uD835\uDDF2\uD835\uDE01\uD835\uDDEE\uD835\uDDF6\uD835\uDDF9\uD835\uDDF2\uD8
# Intuition & Approach\n<!-- Describe your approach to solving the problem. -->\n\uD835\uDDD7\uD835\uDDF2\uD835\uDE01\uD835\uDDEE\uD835\uDDF6\uD835\uDDF9\uD835\uDDF2\uD835\uDDF1 \uD835\uDDD4\uD835\uDDFD\uD835\uDDFD\uD835\uDDFF\uD835\uDDFC\uD835\uDDEE\uD835\uDDF0\uD835\uDDF5 \uD835\uDDD8\uD835\uDE05\uD835\uDDFD\uD835\uDDF9\uD835\uDDEE\uD835\uDDFB\uD835\uDDEE\uD835\uDE01\uD835\uDDF6\uD835\uDDFC\uD835\uDDFB\n\uD835\uDDD6\uD835\uDDFC\uD835\uDDFA\uD835\uDDFA\uD835\uDDF2\uD835\uDDFB\uD835\uDE01\uD835\uDE00 \uD835\uDDEE\uD835\uDDFB\uD835\uDDF1 \uD835\uDDF3\uD835\uDDF2\uD835\uDDF2\uD835\uDDF1\uD835\uDDEF\uD835\uDDEE\uD835\uDDF0\uD835\uDDF8 \uD835\uDDEE\uD835\uDDFF\uD835\uDDF2 \uD835\uDDEE\uD835\uDDFD\uD835\uDDFD\uD835\uDDFF\uD835\uDDF2\uD835\uDDF0\uD835\uDDF6\uD835\uDDEE\uD835\uDE01\uD835\uDDF2\uD835\uDDF1\nhttps://youtu.be/-b9ks62HwEg\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n)\n# Code\n```\nvar minTime = function(n, edges, hasApple) {\n    let children = new Array(n)\n    for (let i = 0; i < n; i++) {\n        children[i] = new Array()\n    }\n    for (let edge of edges) {\n        children[edge[0]].push(edge[1])\n        children[edge[1]].push(edge[0])\n    }\n\n    let res = 0;\n    let dfs = function (node, parent) {\n        let val = false\n        for (let child of children[node]) {\n            if (child === parent) continue\n            res++\n            let bol = dfs(child, node)\n            if (bol) res++\n            else res--\n            val = val || bol\n        }\n        if (hasApple[node]) return true\n        return val\n    }\n    dfs(0)\n    return res\n};\n```
['Hash Table', 'Tree', 'Depth-First Search', 'Recursion', 'JavaScript']