Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake.
Recover the tree without changing its structure.
Example
Example 1:
Input:
[1,3,null,null,2]
1
/
3
\
2
Output:
[3,1,null,null,2]
3
/
1
\
2Example 2:
Note
设置prev指针,找的条件的中序遍历前面比后面的大了,把这两个存下来,交换
Code
Last updated