/* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { } }; */ class Solution { public: int count ; void inorder(TreeNode* root,TreeNode* &ans){ if(root){ inorder(root->left,ans); count--; //会从最小的点开始-- if(!count) ans = root; inorder(root->right,ans); } } TreeNode* KthNode(TreeNode* pRoot, int k) { if(!pRoot || k < 1) return nullptr; TreeNode* ans = NULL; count = k; inorder(pRoot,ans); return ans; } };
原文:https://www.cnblogs.com/Stephen-Jixing/p/13137758.html