30:00
Two nodes of a BST are swapped by mistake. Recover the tree without changing its structure.
The number of nodes is in the range [2,1000][2, 1000][2,1000].
−231≤Node.val≤231−1-2^{31} \leq \text{Node.val} \leq 2^{31} - 1−231≤Node.val≤231−1
Exactly two nodes' values are swapped by mistake.
Initialize first, second, prev to null. Start in-order traversal.
traversing
1
3
2