* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
class Solution {
public:
/**
*
* @param root TreeNode类 the root
* @return int整型vector
*/
vector<int> res;
void preorder(TreeNode* root,int &pre){//pre保存中序遍历前驱节点值
if(!root)return;
preorder(root->left,pre);
if(root->val < pre){
if(res.size() == 0){
res.push_back(root->val);
res.push_back(pre);
}else res[0] = root->val;
}
pre = root->val;
preorder(root->right,pre);
}
vector<int> findError(TreeNode* root) {
// write code here
int t = 0;
preorder(root,t);
return this->res;
}
};