class Solution {
public:
//中序遍历搜索二叉树按递增顺序,除了两个错误节点
//记录错误节点a,b
int a=0;
int b=0;
TreeNode* pre=nullptr;
void inorder(TreeNode* root){
if(!root)
return;
inorder(root->left);
//确定a找到了,找错误节点b
if(pre!=nullptr&&pre->val>root->val&&a!=0)
{
b=root->val;
}
//找寻错误节点a
if(pre!=nullptr&&pre->val>root->val&&a==0)
{
a=pre->val;
}
pre=root; inorder(root->right); } vector<int> findError(TreeNode* root) { // write code here inorder(root); vector<int> res; res.push_back(b); res.push_back(a); return res; }
};