解题思路:
(1)递归中序遍历,计数
(2)保存计数为k的结点
class Solution {
public:
TreeNode* KthNode(TreeNode* pRoot, int k) {
TreeNode* p = NULL;
int count = 0;
inorder(pRoot,p,count,k);
return p;
}
void inorder(TreeNode *root,TreeNode *&p,int &count,int k) {
if(root==NULL) return;
inorder(root->left,p,count,k);
if(++count==k) p=root;
inorder(root->right,p,count,k);
}
};