/**
* @author xienl
* @description 找到搜索二叉树中两个错误的节点
* @date 2022/7/6
*/
public class Solution {
public static void main(String[] args) {
Solution solution = new Solution();
}
int[] res = new int[2];
int i = 0;
public int[] findError (TreeNode root) {
// write code here
dfs(root);
return res;
}
private void dfs(TreeNode root){
if (root == null ){
return;
}
if (root.left != null && root.val < root.left.val){
res[i] = root.val;
} else {
dfs(root.left);
}
if (root.right != null && root.val > root.right.val){
res[i] = root.val;
}else {
dfs(root.right);
}
}
}
class TreeNode {
int val = 0;
TreeNode left = null;
TreeNode right = null;
}