对应代码
/**
* @param root 是一棵错误的二叉搜索树(有2个节点被错误交换)
*/
public void recoverTree1(TreeNode root) {
findWrongNodes(root);
// 交换2个错误节点的值
int tmp = first.val;
first.val = second.val;
second.val = tmp;
}
private void findWrongNodes(TreeNode root) {
if (root == null) return;
findWrongNodes(root.left);
find(root);
findWrongNodes(root.right);
}
}