中序遍历的延伸题
找出二叉搜索树中两个错误的节点
题目来源: leetcode
题目链接
Two elements of a binary search tree (BST) are swapped by mistake.
Recover the tree without changing its structure.
Example 1:
1 | Input: [1,3,null,null,2] |
Example 2:
1 | Input: [3,1,4,null,null,2] |
Follow up:
- A solution using O(n) space is pretty straight forward.
- Could you devise a constant space solution?