C++ 代码
class Solution {
public:
TreeNode* ans;
TreeNode* kthNode(TreeNode* root, int k) {
dfs(root, k);
return ans;
}
void dfs(TreeNode* root, int &k) {
if (!root) return;
dfs(root->left, k);
k --;
if (k == 0) ans = root;
dfs(root->right, k);
}
};