Recover Binary Search Tree
Problem Descriptionβ
You are given the root of a binary search tree (BST), where the values of exactly two nodes of the tree were swapped by mistake. Recover the tree without changing its structure.
Examplesβ
Example 1:
Input: root = [1,3,null,null,2]
Output: [3,1,null,null,2]
Example 2:
Input: root = [3,1,4,null,null,2]
Output: [2,1,4,null,null,3]
Constraintsβ
- The number of nodes in the tree is in the range .