/*
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
TreeNode(int x) :
val(x), left(NULL), right(NULL) {
}
};
*/
class Solution {
int count = 0;
public:
TreeNode* KthNode(TreeNode* pRoot, int k)
{
if(pRoot)
{
TreeNode* ret = KthNode(pRoot->left,k);
if(ret)
return ret;
if(++count==k)
return pRoot;
ret = KthNode(pRoot->right,k);
if(ret)
return ret;
}
return NULL;
}
};
二叉搜索树的第K个节点
最新推荐文章于 2022-02-04 10:47:02 发布