class Solution {
public:
TreeNode* res=NULL;
void mid(TreeNode* root, int k,int &cnt)
{
if(!root)
return;
mid(root->left,k,cnt);
cnt++;
if(cnt==k) res=root;
mid(root->right,k,cnt);
}
TreeNode* kthNode(TreeNode* root, int k) {
int cnt=0;
mid(root,k,cnt);
return res;
}
};
二叉搜索树的第k个结点
发布时间 2023-05-07 17:06:19作者: 穿过雾的阴霾