LeetCode OJ - Recover Binary Search Tree
2014-06-25 09:21
513 查看
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
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
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:
1 / \ 2 3 / 4 \ 5
The above binary tree is serialized as
"{1,2,3,#,#,4,#,#,5}".
相关文章推荐
- 【LeetCode OJ】Recover Binary Search Tree
- LeetCode OJ - Recover Binary Search Tree
- LeetCode OJ-- Recover Binary Search Tree ***@
- LeetCode OJ - Recover Binary Search Tree
- LeetCode OJ:Recover Binary Search Tree
- LeetCode OJ 之 Recover Binary Search Tree(恢复二叉搜索树)
- LeetCode: Recover Binary Search Tree
- [leetcode]Recover Binary Search Tree
- Recover Binary Search Tree
- Recover Binary Search Tree
- [Leetcode] Validate Binary Search Tree & Recover Binary Search Tree
- 99. Recover Binary Search Tree
- (leetcode 99) Recover Binary Search Tree
- leetcode--Recover Binary Search Tree*
- 99. Recover Binary Search Tree
- Recover Binary Search Tree
- LeetCode算法题目:Recover Binary Search Tree
- leetcode Recover Binary Search Tree
- LeetCode99—Recover Binary Search Tree
- LeetCode OJ 之 Convert Sorted List to Binary Search Tree(把有序链表转化为二叉搜索树)