C# Solution With Stack
\n    public class Solution\n    {\n        private void Find(TreeNode node, TreeNode target, Stack<TreeNode> path)\n        {\n            if (node == null)\n 
```\n    public class Solution\n    {\n        private void Find(TreeNode node, TreeNode target, Stack<TreeNode> path)\n        {\n            if (node == null)\n            {\n                return;\n            }\n\n            path.Push(node);\n\n            if (node == target)\n            {\n                return;\n            }\n\n            Find(node.left, target, path);\n            if (path.Peek() != target)\n            {\n                Find(node.right, target, path);\n            }\n\n            if (path.Peek() != target)\n            {\n                path.Pop();\n            }\n        }\n\n        private void Dfs(TreeNode node, ISet<TreeNode> visited, int k, IList<int> res)\n        {\n            if (node == null)\n            {\n                return;\n            }\n\n            if (!visited.Add(node))\n            {\n                return;\n            }\n\n            if (k == 0)\n            {\n                res.Add(node.val);\n                return;\n            }\n\n            Dfs(node.left, visited, k - 1, res);\n            Dfs(node.right, visited, k - 1, res);\n        }\n\n        public IList<int> DistanceK(TreeNode root, TreeNode target, int k)\n        {\n            IList<int> res = new List<int>();\n            Stack<TreeNode> path = new Stack<TreeNode>();\n            Find(root, target, path);\n\n            ISet<TreeNode> visited = new HashSet<TreeNode>();\n\n            while (path.Count > 0 && k >= 0)\n            {\n                Dfs(path.Pop(), visited, k--, res);\n            }\n\n            return res;\n        }\n    }\n```
['Stack', 'Depth-First Search']