java DFS code with Comments
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    // Function to find the minimum time to collect all apples\n    public int minTime(int n, int[][] edges, List<Boolean> hasApple) {\n        // Create an adjacency list to represent the tree\n        List<List<Integer>> adj = new ArrayList<>();\n        for(int i = 0; i < n; i++){\n            adj.add(new ArrayList<>());\n        }\n        // populate the adjacency list\n        for(int [] edge : edges){\n            adj.get(edge[0]).add(edge[1]);\n            adj.get(edge[1]).add(edge[0]);\n\n        }\n        // call to helper function to find the minimum time\n        return minTimeToCollectApples(0, adj, hasApple, 0);\n    }\n    // Helper function\n    int minTimeToCollectApples(int index, List<List<Integer>> adj, List<Boolean> hasApple, int parent){\n        // variable to keep track of total time\n        int total = 0;\n        // for each neighbor of current node\n        for(int nbr : adj.get(index)){\n            // if the neighbor is the parent node, then we skip\n            if (nbr == parent)\n             continue;\n            // we recursively call the helper function for each neighbor\n            total += minTimeToCollectApples(nbr, adj, hasApple, index);\n        }\n        // If current node is not the root (0th) node, and it has an apple or any of its descendant has\n        //  then we need to add 2 time for moving to and from it\n        if( index != 0 && (hasApple.get(index) || total > 0))\n          total += 2;\n        return total;\n    }\n}\n\n```
['Java']