Practice Recover Binary Search Tree
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Medium#99
LeetCode ProblemRecover Binary Search Tree
Problem Statement
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.
Source: Recover Binary Search Tree on LeetCode. Use the original task for its coding environment and submissions.
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 [2, 1000].
-2^31 <= Node.val <= 2^31 - 1
Related LeetCode Problems
Practice more problems similar to Recover Binary Search Tree.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.