GoLang Solution For LeetCode Problem: Recover Binary Search Tree
Solving Recover Binary Search Tree in go. Please try yourself first to solve the problem and submit your implementation to LeetCode before looking into solution.
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] 1 / 3 \ 2 Output: [3,1,null,null,2] 3 / 1 \ 2
Input: [3,1,4,null,null,2] 3 / \ 1 4 / 2 Output: [2,1,4,null,null,3] 2 / \ 1 4 / 3
- A solution using O(n) space is pretty straight forward.
- Could you devise a constant space solution?
See the full details of the problem Recover Binary Search Tree at LeetCode
Originally posted at: @github.com/halfrost/LeetCode-Go