Amex SPG卡送25K points 免费送500刀现金 最佳酒店卡# Movie - 无限影话
H*M
1 楼
1. given a binary tree ,find the largest sub-tree which is a BST...(largest
mea
ns subtree having largest no of nodes in it)
我的理解是subtree就是说是一个子树,比如要到原来树的leaf,而不能把原来树的inter
nal nodes做leaf.也就是不能中间截一块,是这样的吗?
有什么好方法.我写的特别繁琐.if else 很多,用recursion.
2. 第二题说,design n stacks in an array of N. 这个我想愿意肯定不是让一个
stack分派固定的.感觉是要综合调配的,比如,如果array还有空,就不能说某个stack不
能加入了.我
想法是keep一个free list,,每个stack元素都要有个Next的指针,指向下个元素,stack
push的时候,就从freelist里面取.这样stack的元素就不连续了.
有什么其它的好办法么?
mea
ns subtree having largest no of nodes in it)
我的理解是subtree就是说是一个子树,比如要到原来树的leaf,而不能把原来树的inter
nal nodes做leaf.也就是不能中间截一块,是这样的吗?
有什么好方法.我写的特别繁琐.if else 很多,用recursion.
2. 第二题说,design n stacks in an array of N. 这个我想愿意肯定不是让一个
stack分派固定的.感觉是要综合调配的,比如,如果array还有空,就不能说某个stack不
能加入了.我
想法是keep一个free list,,每个stack元素都要有个Next的指针,指向下个元素,stack
push的时候,就从freelist里面取.这样stack的元素就不连续了.
有什么其它的好办法么?