avatar
问一道amazon面试题# JobHunting - 待字闺中
M*e
1
原题见这里
http://www.glassdoor.com/Interview/Given-a-list-of-structs-whic
Given a list of structs which include two ids of parent node and the
associated child node, construct a tree.
Interview Candidate: 说
The solution should use O(n) time and O(n) space.
The idea is to hash ids (parent id - child id). The the linear scan
constructs the tree.
怎么感觉还是不明白.谁知道的给解释一下。
谢谢
avatar
g*y
2
the.hash table should look like parentid:child1id, child2id, ...

【在 M******e 的大作中提到】
: 原题见这里
: http://www.glassdoor.com/Interview/Given-a-list-of-structs-whic
: Given a list of structs which include two ids of parent node and the
: associated child node, construct a tree.
: Interview Candidate: 说
: The solution should use O(n) time and O(n) space.
: The idea is to hash ids (parent id - child id). The the linear scan
: constructs the tree.
: 怎么感觉还是不明白.谁知道的给解释一下。
: 谢谢

avatar
k*g
3
hashtable应该是id->node
class Node {
int id;
ArrayList children;
}
接下去读一遍分别连连起来就可以了
avatar
c*5
4
How could we find the root node?
Thanks.

【在 k***g 的大作中提到】
: hashtable应该是id->node
: class Node {
: int id;
: ArrayList children;
: }
: 接下去读一遍分别连连起来就可以了

avatar
D*f
5
其实没必要hash,另外申请一数组,放入结构{int pid, int cid, Node*}.当然,可以
认为这个数组就是hash表。
avatar
T*n
6
只在parent id中出现,没有在children id中出现的就是root, 先找到root,然后递归
的构建每个
root的children的子树。

【在 c******5 的大作中提到】
: How could we find the root node?
: Thanks.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。