由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - L家电面(最新) 攒RP 求bless
相关主题
请教个G题目问一道G家热题
一道面试题construct bst from post and inorder 总是Memory Limit Exceeded
问个amazon面试题再来一道简单的bit运算题
求教一道老题问道题,binary tree里有一个有indegree 2
白痴问题:TreeNode 里面有指向 parent 的指针么?Lowest common ancestor of two nodes of Binary Tree
Zilow在线测试Twitter电面未通过
amazon一道面试题在版上看到的G题
construct tree with preorder and inorderCareercup question.
相关话题的讨论汇总
话题: node话题: public话题: parent话题: tree话题: integer
进入JobHunting版参与讨论
1 (共1页)
x******u
发帖数: 259
1
运气不好,碰到老印三哥三姐,悲剧了。电话进来Late了。然后讨论简历。。。
上题,头有点晕。。。把题弄错了。一开始思路不对,就悲剧了。
Given a list of child->parent relationships, build a binary tree out of it.
All the element Ids inside the tree are unique.
Example:
Given the following relationships:
Child Parent IsLeft
15 20 true
19 80 true
17 20 false
16 80 false
80 50 false
50 null false
20 50 true
You should return the following tree:
50
/
20 80
/ /
15 17 19 16
Function Signature

/**
* Represents a pair relation between one parent node and one child node
inside a binary tree
* If the _parent is null, it represents the ROOT node
*/
public class Relation {
public Integer _parent;
public Integer _child;
public boolean _isLeft;
}
/**
* Represents a single Node inside a binary tree
*/
public class Node {
public Integer _id;
public Node _left;
public Node _right;
}
/**
* Implement a method to build a tree from a list of parent-child
relationships
* And return the root Node of the tree
*/
public Node buildTree (List data)
{
//TODO
}
f*******w
发帖数: 1243
2
id是unique的,那就挨个读把node pointer存到hash里,id是key呗
l*****a
发帖数: 14598
3
thanks for sharing.
搞个Map存结果
if Parent==null then it is ROOT.

.

【在 x******u 的大作中提到】
: 运气不好,碰到老印三哥三姐,悲剧了。电话进来Late了。然后讨论简历。。。
: 上题,头有点晕。。。把题弄错了。一开始思路不对,就悲剧了。
: Given a list of child->parent relationships, build a binary tree out of it.
: All the element Ids inside the tree are unique.
: Example:
: Given the following relationships:
: Child Parent IsLeft
: 15 20 true
: 19 80 true
: 17 20 false

x******u
发帖数: 259
4
嗯,开始没想到hash,当时脑子进水了:(
1 (共1页)
进入JobHunting版参与讨论
相关主题
Careercup question.白痴问题:TreeNode 里面有指向 parent 的指针么?
python里面怎么表示树?Zilow在线测试
L家这题咋搞,巨变态amazon一道面试题
[google面试]iterator访问construct tree with preorder and inorder
请教个G题目问一道G家热题
一道面试题construct bst from post and inorder 总是Memory Limit Exceeded
问个amazon面试题再来一道简单的bit运算题
求教一道老题问道题,binary tree里有一个有indegree 2
相关话题的讨论汇总
话题: node话题: public话题: parent话题: tree话题: integer