由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - construct bst from post and inorder 总是Memory Limit Exceeded
相关主题
Construct Binary Tree from Inorder and Postorder TraversalAmazon 电面
讨论一道leetcode上面的题LeetCode construct Binary Tree
[leetcode] Binary Tree from Inorder & Postorder Traversal全部答出来了,还是被amazon onsite据了
Construct Binary Tree from Preorder and Inorder Traversal算法复杂度?这个inorder traversal 有错嘛,为什么leetcode 总报memory limit exceed?
construct tree with preorder and inorderinorder traversal的空间复杂度是O(N) 还是O(logN)?
Tree的traversal也分BFS和DFS?请问一道关于binary tree的题
攒人品,amazon一面经历过不了leetcode Zigzag Level Order Traversal
现在怎么都是讨论offer的,没有做题的了?这个rebuild binary tree的问题
相关话题的讨论汇总
话题: inorder话题: postorder话题: mid话题: return话题: treenode
进入JobHunting版参与讨论
1 (共1页)
f********a
发帖数: 165
1
class Solution:
# @param inorder, a list of integers
# @param postorder, a list of integers
# @return a tree node
def buildTree(self, inorder, postorder):
n = len(inorder)
if n == 0:
return None
elif n == 1:
return TreeNode(postorder[-1])
else:
root = TreeNode(postorder[-1])
mid_inorder = inorder.index(postorder[-1])
root.left = self.buildTree(inorder[:mid_inorder], postorder[:mid
_inorder])
root.right = self.buildTree(inorder[mid_inorder+1:], postorder[
mid_inorder:-1])
return root
是因为inorder[:mid_inorder]重新拷贝了一份substring所以递归就超内存了?
1 (共1页)
进入JobHunting版参与讨论
相关主题
这个rebuild binary tree的问题construct tree with preorder and inorder
问一道G家热题Tree的traversal也分BFS和DFS?
请教个G题目攒人品,amazon一面经历
问几个有关Binary tree的题现在怎么都是讨论offer的,没有做题的了?
Construct Binary Tree from Inorder and Postorder TraversalAmazon 电面
讨论一道leetcode上面的题LeetCode construct Binary Tree
[leetcode] Binary Tree from Inorder & Postorder Traversal全部答出来了,还是被amazon onsite据了
Construct Binary Tree from Preorder and Inorder Traversal算法复杂度?这个inorder traversal 有错嘛,为什么leetcode 总报memory limit exceed?
相关话题的讨论汇总
话题: inorder话题: postorder话题: mid话题: return话题: treenode