Java || Depth First
\nclass Solution {\n    List<Integer> answer = new ArrayList<>();\n    Map<TreeNode, TreeNode> childParentMap = new HashMap<>();\n    Set<TreeNode> visited = ne
```\nclass Solution {\n    List<Integer> answer = new ArrayList<>();\n    Map<TreeNode, TreeNode> childParentMap = new HashMap<>();\n    Set<TreeNode> visited = new HashSet<>();\n    \n    public List<Integer> distanceK(TreeNode root, TreeNode target, int k) {\n        findParent(root);\n        depthFirst(target, k);\n        return answer;\n    }\n    \n    private void findParent(TreeNode node) {\n        if(node == null) {\n            return;\n        }\n        if(node.left != null) {\n            childParentMap.put(node.left, node);\n            findParent(node.left);\n        }\n        if(node.right != null) {\n            childParentMap.put(node.right, node);\n            findParent(node.right);\n        }\n    }\n    \n    private void depthFirst(TreeNode node, int k) {\n        if(node == null || visited.contains(node)) {\n            return;\n        }\n        visited.add(node);\n        if(k == 0) {\n            answer.add(node.val);\n            return;\n        }\n        depthFirst(node.left, k-1);\n        depthFirst(node.right, k-1);\n        depthFirst(childParentMap.get(node), k-1);\n    }\n}\n```
['Depth-First Search', 'Java']