99. Recover Binary Search Tree
Last updated
Was this helpful?
Last updated
Was this helpful?
Two elements of a binary search tree (BST) are swapped by mistake.
Recover the tree without changing its structure.
Input: [1, 3, null, null, 2]
Output: [3, 1, null, null, 2]
A solution using O(n) space is pretty straight forward.
Could you devise a constant space solution?