99. Recover Binary Search Tree

Description

Two elements of a binary search tree (BST) are swapped by mistake.

Recover the tree without changing its structure.

Constraints

Approach

Examples

Input: [1, 3, null, null, 2]

Output: [3, 1, null, null, 2]

Solutions

Follow up

  • A solution using O(n) space is pretty straight forward.

  • Could you devise a constant space solution?

Last updated

Was this helpful?