C++ | 90% Faster | Short & Concise
\n    vector<TreeNode*> path(TreeNode *root, int val) {\n        if(!root) return {};\n        if(root->val == val) return {root};\n        vector<TreeNode*> l,
```\n    vector<TreeNode*> path(TreeNode *root, int val) {\n        if(!root) return {};\n        if(root->val == val) return {root};\n        vector<TreeNode*> l, r;\n        l = path(root->left, val);\n        r = path(root->right, val);\n        if(l.size()) {l.push_back(root); return l;}\n        if(r.size()) {r.push_back(root); return r;}\n        return {};\n    }\n    \n    void distance(TreeNode *root, int k, TreeNode* before, vector<int> &ans) {\n        if(!root || root == before) return;\n        distance(root->left, k - 1, before, ans);\n        distance(root->right, k - 1, before, ans);\n        if(k == 0) ans.push_back(root->val);\n        return;\n    }\n    \n    vector<int> distanceK(TreeNode* root, TreeNode* target, int k) {\n        vector<TreeNode*> v = path(root, target->val);\n        vector<int> ans;\n        for(int i = 0; i < v.size() && k >= i; i++)\n            distance(v[i], k - i, i == 0 ? NULL : v[i - 1], ans);\n        return ans;\n    }\n```
['Tree', 'Depth-First Search', 'Binary Tree']