由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问一道leetcode题:recover BST
相关主题
recover binary search tree 常数空间恢复错误的BST
Leetcode Recover Binary Search Tree一问一个GOOG的二叉树面试题
leetcode里面的Recover Binary Search Tree怎么用O(1)space求教:binary search tree中找第i大的数
请教一个BST找Median的题目树 inorder下个节点最好办法是啥
一道msft的题判断(二叉)树是否镜像对称
BST 找重复节点数问一道二叉树遍历的问题? 谢谢!
How to find the kth biggest number in a BSTFind the node with given value in binary tree in in-order
find kth smallest key in BST with O(lgn)F家phone interview的一道题
相关话题的讨论汇总
话题: bst话题: recover话题: leetcode话题: tree话题: 一道
进入JobHunting版参与讨论
1 (共1页)
b**u
发帖数: 45
1
http://oj.leetcode.com/problems/recover-binary-search-tree/
Two elements of a binary search tree (BST) are swapped by mistake.
Recover the tree without changing its structure.
note说O(n) space straightforward,我怎么不觉得?要结构和原来一样,想不出O(n)
有什么明显解法。谁说说思路?
A*********c
发帖数: 430
2
inorder遍历,此过程中建立两个数组,一个顺序存所有的Node地址,一个顺序存所有
的node值。
这步,相当于建立了一对儿parallel array.
Inorder产生的值数组应该是排好序的,但是不是,因为两个值错位了。
linear scan值数组。找到错位的两个index,然后去对调node地址array中相应的index
,这步是O(n), O(1).

n)

【在 b**u 的大作中提到】
: http://oj.leetcode.com/problems/recover-binary-search-tree/
: Two elements of a binary search tree (BST) are swapped by mistake.
: Recover the tree without changing its structure.
: note说O(n) space straightforward,我怎么不觉得?要结构和原来一样,想不出O(n)
: 有什么明显解法。谁说说思路?

y*****3
发帖数: 451
3
不是很懂LZ在说什么,为什么保持结构一样就无法O(n) space了?

n)

【在 b**u 的大作中提到】
: http://oj.leetcode.com/problems/recover-binary-search-tree/
: Two elements of a binary search tree (BST) are swapped by mistake.
: Recover the tree without changing its structure.
: note说O(n) space straightforward,我怎么不觉得?要结构和原来一样,想不出O(n)
: 有什么明显解法。谁说说思路?

l******a
发帖数: 64
4
中序遍历,记录不符合顺序的情况,in place 替换,时间复杂度O(n), 空间复杂度O(1
)
1 (共1页)
进入JobHunting版参与讨论
相关主题
F家phone interview的一道题一道msft的题
MS面试题BST 找重复节点数
谁有较好的iterative后序遍历binary tree的代码?How to find the kth biggest number in a BST
一道二叉树的老题find kth smallest key in BST with O(lgn)
recover binary search tree 常数空间恢复错误的BST
Leetcode Recover Binary Search Tree一问一个GOOG的二叉树面试题
leetcode里面的Recover Binary Search Tree怎么用O(1)space求教:binary search tree中找第i大的数
请教一个BST找Median的题目树 inorder下个节点最好办法是啥
相关话题的讨论汇总
话题: bst话题: recover话题: leetcode话题: tree话题: 一道