very easy to understand c++ solution.
Using recursion to find all of the son=>parent pair into a map.\n2. Using dfs to find K distance node, visited nodes will be recorded.\n\nclass Solution {\npubl
1. Using recursion to find all of the son=>parent pair into a map.\n2. Using dfs to find K distance node, visited nodes will be recorded.\n```\nclass Solution {\npublic:\n    vector<int> ans;   \n    map<TreeNode*, TreeNode*> parent;  // son=>parent  \n    set<TreeNode*> visit;    //record visied node\n    \n    void findParent(TreeNode* node){\n        if(!node ) return;\n        if( node->left ){\n            parent[node->left] = node;\n            findParent(node->left);\n        }\n        if( node->right){\n            parent[node->right] = node;\n            findParent(node->right);\n        }\n    }\n    \n    vector<int> distanceK(TreeNode* root, TreeNode* target, int K) {\n        if( !root ) return {};\n        \n        findParent(root);\n        dfs(target, K );\n        return ans;\n    }\n    void dfs( TreeNode* node, int K){\n        if( visit.find(node) != visit.end() )\n            return;\n        visit.insert(node);\n        if( K == 0 ){\n            ans.push_back(node->val);\n            return;\n        }\n        if( node->left ){\n            dfs(node->left, K-1);\n        }\n        if( node->right){\n            dfs(node->right, K-1);\n        }\n        TreeNode* p = parent[node];\n        if( p )\n            dfs(p, K-1);\n    }\n};\n```
[]