由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 回馈本版,新鲜店面,新题新气象
相关主题
请教个G题目发现一个很恶心的基础问题
热腾腾的 LinkedIn 电面题攒RPFind the node with given value in binary tree in in-order
一道google面试题一道在线题
yahoo onsite请问怎么样才能想到关于tree等比较简洁的答案呢?同时记一下超慢速刷题过半以鼓励自己
Interview question::请教一道g算法题
mirror 一个binary tree, 用non-recursive解法怎么做FB面经
大虾帮忙看看代码,为什么 res参数传入不了,返回总是null求教Leetcode题目:Lowest Common Ancestor
问题在哪儿啊 kth Node of BST,大家帮忙Find a sub tree with min weight怎么做
相关话题的讨论汇总
话题: treenode话题: root话题: node话题: null话题: left
进入JobHunting版参与讨论
1 (共1页)
D***0
发帖数: 138
1
二面,现在真是店面还流行二进宫,依然还是做题,然后onsite还是做题,把做题进行
到底吧。
从昨晚接到recruiter的email通知换把一个国人大哥换成了不知哪国人,就有不祥预感
,另外一个是刚加入的一个小三姐。本来以为是这个senior出题,这小三姐在旁听着,
结果这大哥上来就说,翠花,上酸菜吧,小三姐可是毫不客气的把一道新题无情的砸向
了脆弱心灵的我(:)大家别扔鸡蛋啊),废话少说,书归正文:
Given a binary tree where all the right nodes are either empty or leaf nodes
, flip it upside down and turn it into a tree with left leaf nodes.
In the original tree, if a node has right child, it must has left child.
for example, turn these:
1 1
/ /
2 3 2 3
/
4
/
5 6
into these:
1 1
/ /
2---3 2---3
/
4
/
5---6
where 5 is the new root node for the left tree, and 2 for the right tree.
oriented correctly:
5 2
/ /
6 4 3 1

2
/
3 1
她说这个他们新题中的一道,可见大家以后有好几壶够喝的了。
最后磕磕绊绊的总是做出来了。
带头大哥说,来变个型,条件一样,给哥整成这样:
1 1
/ /
2 2
/
4 3 3
/
5

6
哎,实力有限,遇到新题就像遇见丈母娘一样,求个bless,能给个onsite吧。
a***d
发帖数: 5
2
尝试写一个
TreeNode* ConvertTree(TreeNode *root)
{
if(!root) return NULL;
if(!root->left && !root->right) return root;
TreeNode* res=ConvertTree(root->left);
root->left->left=root->right;
root->left->right=root;
root->left=root->right=NULL;
return res;
}
l******6
发帖数: 340
3
TreeNode* upDown(TreeNode* root)
{
if(!root)
return root;
TreeNode* rightCousin = NULL;
TreeNode* parent = NULL;
TreeNode* temp;
while(root)
{
temp = root -> left;
root -> left = rightCousin;
rightCousin = root -> right;
root -> right = parent;
parent = root;
root = temp;
}
if(rightCousin)
{
rightCousin->left = parent;
return rightCousin;
}
return parent;
}
u*****o
发帖数: 1224
4
哈哈cousin这名字挺形象的
a********9
发帖数: 129
5
linkedin?
t******i
发帖数: 483
6
google?
c********e
发帖数: 186
7
bless!
D**********d
发帖数: 849
8
Node* Insert(Node* root, Node* n){
if(!root) return root;
Node*t = root->right;
root->right = n;
if(root->left){
return Insert(root->left,t);
}else{
return root;
}
}
// initially call Node* NewRoot = Insert(root,NULL);
D****3
发帖数: 611
9
l家面过这题
m**********4
发帖数: 774
10
多谢LZ分享。试着写了一会儿,花了挺长时间才想清楚。估计要是被面肯定挂了,时间
太长要是三姐再干扰干扰根本没可能想清楚。
JAVA:
Iterative version, 应该和reverse linkedlist差不多,但要多记录几个NODE的值
public TreeNode convert(TreeNode tn){
if (tn == null)
return tn;
TreeNode curr = tn;
TreeNode prevLeft = null;
TreeNode prevRight = null;
while (curr != null){
TreeNode currLeft = curr.left;
TreeNode currRight = curr.right;
curr.left = prevRight;
curr.right = prevLeft;
prevLeft = curr;
curr = currLeft;
prevRight = currRight;
}
return prevLeft;
}
Recursive:
JAVA木有指针,不好改动,所以做一个NodePair class记录转换过的HEAD 和TAIL。
class NodePair{
TreeNode head;
TreeNode tail;
NodePair(TreeNode h, TreeNode t){
head = h;
tail = t;
}
}
public NodePair convert2(TreeNode node, TreeNode rightNode){
TreeNode next = node.left;
if (next == null){
node.left = rightNode;
return new NodePair(node, node);
}else{
TreeNode rightTmp = node.right;
NodePair np = convert2(next, rightTmp);
node.left = rightNode;
node.right = null;
np.tail.right = node;
return new NodePair(np.head, node);
}
}

nodes

【在 D***0 的大作中提到】
: 二面,现在真是店面还流行二进宫,依然还是做题,然后onsite还是做题,把做题进行
: 到底吧。
: 从昨晚接到recruiter的email通知换把一个国人大哥换成了不知哪国人,就有不祥预感
: ,另外一个是刚加入的一个小三姐。本来以为是这个senior出题,这小三姐在旁听着,
: 结果这大哥上来就说,翠花,上酸菜吧,小三姐可是毫不客气的把一道新题无情的砸向
: 了脆弱心灵的我(:)大家别扔鸡蛋啊),废话少说,书归正文:
: Given a binary tree where all the right nodes are either empty or leaf nodes
: , flip it upside down and turn it into a tree with left leaf nodes.
: In the original tree, if a node has right child, it must has left child.
: for example, turn these:

y***n
发帖数: 1594
11
这个题不错,Leetcode 可以收入。
p****o
发帖数: 46
12
it is quite like to process a linkedlist.
不过没太看懂变型的要求, 有什么区别?

nodes

【在 D***0 的大作中提到】
: 二面,现在真是店面还流行二进宫,依然还是做题,然后onsite还是做题,把做题进行
: 到底吧。
: 从昨晚接到recruiter的email通知换把一个国人大哥换成了不知哪国人,就有不祥预感
: ,另外一个是刚加入的一个小三姐。本来以为是这个senior出题,这小三姐在旁听着,
: 结果这大哥上来就说,翠花,上酸菜吧,小三姐可是毫不客气的把一道新题无情的砸向
: 了脆弱心灵的我(:)大家别扔鸡蛋啊),废话少说,书归正文:
: Given a binary tree where all the right nodes are either empty or leaf nodes
: , flip it upside down and turn it into a tree with left leaf nodes.
: In the original tree, if a node has right child, it must has left child.
: for example, turn these:

s*********9
发帖数: 53
13
哪家公司啊?
1 (共1页)
进入JobHunting版参与讨论
相关主题
Find a sub tree with min weight怎么做Interview question::
渣渣cs本科半应届如何找工作mirror 一个binary tree, 用non-recursive解法怎么做
Lowest Common Ancestor大虾帮忙看看代码,为什么 res参数传入不了,返回总是null
Amazon 打印给定node距离最近的K个nodes问题在哪儿啊 kth Node of BST,大家帮忙
请教个G题目发现一个很恶心的基础问题
热腾腾的 LinkedIn 电面题攒RPFind the node with given value in binary tree in in-order
一道google面试题一道在线题
yahoo onsite请问怎么样才能想到关于tree等比较简洁的答案呢?同时记一下超慢速刷题过半以鼓励自己
相关话题的讨论汇总
话题: treenode话题: root话题: node话题: null话题: left