leetcode之recover-binary-search-tree(搜索二叉树BST重建)
题目
Two elements of a binary search tree (BST) are swapped by mistake.
Recover the tree without changing its structure.
Note:
A solution using O(n ) space is pretty straight forward. Could you devise a constant space solution?
confused what"{1,#,2,3}"means? > read more on how binary tree is serialized on OJ.
OJ’s Binary Tree Serialization:
The serialization of a binary tree follows a level order traversal, where ‘#’ signifies a path terminator where no node exists below.
Here’s an example:
The above binary tree is serialized as"{1,2,3,#,#,4,#,#,5}".
题意
给定一颗二叉树,这个二叉树要求在O(n)的额外空间中,将其重新排序为一颗BTS,搜索二叉树。