avatar
R*s
1
家常丑菜又来了。。。健康又快捷哈
羊肉萝卜汤:
带骨羊肉两大块, 过水, 切成小块, 萝卜也切小块, 一起扔
电高压锅煮, 15分钟, 出锅的时候加盐, 胡椒, 香菜。
熏火鸡脖子:
昨天本来想买火鸡腿的, 只找到脖子。 蒸锅先蒸上, 这时候可
以做别的菜, 最后出锅加点Jalapeno和蒜炒一下就好了。
香菇白菜:
香菇泡一下, 白菜洗干净, 扯一半, 下锅, 加点水煮下下。
微波红薯:
红薯扔微波炉高温6分钟,完事。
avatar
c*y
2
Given a binary tree
struct node{
struct node* leftChild;
struct node* rightChild;
struct node* nextRight;
}
The nextRight points to the right node to the current node in the same
level. Ask you populate the nextRight pointers in each node.
大家怎么做这道题.
avatar
s*l
3
不错不错,学习了
avatar
m*f
4
记得以前有个分level打印二叉树的题目么, 这两道题本质上是一样的
avatar
d*e
5
###此帖已应当事人要求删除###
avatar
a*g
6
BFS

【在 c*****y 的大作中提到】
: Given a binary tree
: struct node{
: struct node* leftChild;
: struct node* rightChild;
: struct node* nextRight;
: }
: The nextRight points to the right node to the current node in the same
: level. Ask you populate the nextRight pointers in each node.
: 大家怎么做这道题.

avatar
s*i
7
赞,你家的伙食总是很丰盛
avatar
c*y
8
对,就是每个node从queue里面dequeue出来后它的nextRight指向queue的peek。
我现在在想,能否有recursion的方法?想了下想不出来。

【在 m*****f 的大作中提到】
: 记得以前有个分level打印二叉树的题目么, 这两道题本质上是一样的
avatar
s*i
9
熏火鸡脖子色泽诱人,令人食指大动!
为什么叫“熏”,买的是熏过的吗?
avatar
b*j
10
可以使用任何方式遍历一遍这棵树,iterative or recurise
在遍历过程中,对每一个节点x
if (x->leftChild and x->rightChild) {
x->leftChild->nextRight = x->rightChild;
x->rightChild->nextRight = 0;
}

【在 c*****y 的大作中提到】
: Given a binary tree
: struct node{
: struct node* leftChild;
: struct node* rightChild;
: struct node* nextRight;
: }
: The nextRight points to the right node to the current node in the same
: level. Ask you populate the nextRight pointers in each node.
: 大家怎么做这道题.

avatar
c*u
11
赞啊!你买的火鸡脖子本来就是熟的么?

【在 R*****s 的大作中提到】
: 家常丑菜又来了。。。健康又快捷哈
: 羊肉萝卜汤:
: 带骨羊肉两大块, 过水, 切成小块, 萝卜也切小块, 一起扔
: 电高压锅煮, 15分钟, 出锅的时候加盐, 胡椒, 香菜。
: 熏火鸡脖子:
: 昨天本来想买火鸡腿的, 只找到脖子。 蒸锅先蒸上, 这时候可
: 以做别的菜, 最后出锅加点Jalapeno和蒜炒一下就好了。
: 香菇白菜:
: 香菇泡一下, 白菜洗干净, 扯一半, 下锅, 加点水煮下下。
: 微波红薯:

avatar
c*y
12
这个主要看如何理解这道题,如果认为nextRight是指向同一parent点下的右边点,你
可以这么做。
如果是指同一level的右边点,那么只能用bfs了。

【在 b****j 的大作中提到】
: 可以使用任何方式遍历一遍这棵树,iterative or recurise
: 在遍历过程中,对每一个节点x
: if (x->leftChild and x->rightChild) {
: x->leftChild->nextRight = x->rightChild;
: x->rightChild->nextRight = 0;
: }

avatar
R*s
13
哈哈, 是挺粗的, 不过味道不错, 比鸭脖子好啃 :)

【在 d**e 的大作中提到】
: ###此帖已应当事人要求删除###
avatar
b*j
14
I see, then BFS!

【在 c*****y 的大作中提到】
: 这个主要看如何理解这道题,如果认为nextRight是指向同一parent点下的右边点,你
: 可以这么做。
: 如果是指同一level的右边点,那么只能用bfs了。

avatar
R*s
15
嗯, 熏过的, 我们这里超市老卖熏火鸡翅膀啊火鸡腿啊啥的。。
蒸一下就可以吃。。。

【在 s*******i 的大作中提到】
: 熏火鸡脖子色泽诱人,令人食指大动!
: 为什么叫“熏”,买的是熏过的吗?

avatar
b*e
16
这题水深了. 你的研究客户心理. 明显不是BFS. 对于平衡树来讲, BFS的space
complexity
是O(n)的. DFS一般是O(log(n))的. 一般树都比较平衡, 否则比较傻逼. 这个分三步:
第一步, 如果有parent pointer, 就就这么做:
void linkNext(node * current) {
if (!current) {
return;
}
if (current->nextRight) {
return;
}
node * parent = current->parent;
if (!parent) {
current->nextRight = NULL;
} else if (current == parent->leftChild && parent->rightChild) {
current->nextRight = parent->rightChild;
} else {
node

【在 c*****y 的大作中提到】
: 对,就是每个node从queue里面dequeue出来后它的nextRight指向queue的peek。
: 我现在在想,能否有recursion的方法?想了下想不出来。

avatar
a*l
17
版大威武!

【在 R*****s 的大作中提到】
: 家常丑菜又来了。。。健康又快捷哈
: 羊肉萝卜汤:
: 带骨羊肉两大块, 过水, 切成小块, 萝卜也切小块, 一起扔
: 电高压锅煮, 15分钟, 出锅的时候加盐, 胡椒, 香菜。
: 熏火鸡脖子:
: 昨天本来想买火鸡腿的, 只找到脖子。 蒸锅先蒸上, 这时候可
: 以做别的菜, 最后出锅加点Jalapeno和蒜炒一下就好了。
: 香菇白菜:
: 香菇泡一下, 白菜洗干净, 扯一半, 下锅, 加点水煮下下。
: 微波红薯:

avatar
v*t
18
其实从上往下,遍历一层链的过程中链接下一层链,这样就不需要parent指针了。因为
在生成下一层链的时候,当前的这个节点就是下一层的parent。

步:

【在 b***e 的大作中提到】
: 这题水深了. 你的研究客户心理. 明显不是BFS. 对于平衡树来讲, BFS的space
: complexity
: 是O(n)的. DFS一般是O(log(n))的. 一般树都比较平衡, 否则比较傻逼. 这个分三步:
: 第一步, 如果有parent pointer, 就就这么做:
: void linkNext(node * current) {
: if (!current) {
: return;
: }
: if (current->nextRight) {
: return;

avatar
R*s
19
不晓得啊, 熏过的, 我一般是要蒸一下, 至少蒸15分钟吧,
完了直接就能吃, 我一般回下锅, 加点蒜啥的炒炒更香~

【在 c*******u 的大作中提到】
: 赞啊!你买的火鸡脖子本来就是熟的么?
avatar
b*e
20
没说到点上。
其实这题的意思是用nextRight来代替queue, 不要新空间。 就像用parent来代替栈一
样。

【在 v*****t 的大作中提到】
: 其实从上往下,遍历一层链的过程中链接下一层链,这样就不需要parent指针了。因为
: 在生成下一层链的时候,当前的这个节点就是下一层的parent。
:
: 步:

avatar
l*3
21
先顶下,看着真好吃。。。
avatar
g*y
22
在一层上遍历完了一条链(由nextRight串起来的链)生成下一层新的一条链,然后再遍历新的链继续生成新的链。。。这不就相当于是用nextRight代替queue嘛
当然,没有你表述的那么清晰,呵呵
有了queue就不需要stack了,所以不需要用到parent了嘛

【在 b***e 的大作中提到】
: 没说到点上。
: 其实这题的意思是用nextRight来代替queue, 不要新空间。 就像用parent来代替栈一
: 样。

avatar
R*s
23
细细, 比特厨的差远了, 没办法, 这不是一下能赶上来的。。。

【在 l********3 的大作中提到】
: 先顶下,看着真好吃。。。
avatar
m*f
24
一针见血啊, 明白了

【在 b***e 的大作中提到】
: 没说到点上。
: 其实这题的意思是用nextRight来代替queue, 不要新空间。 就像用parent来代替栈一
: 样。

avatar
s*i
25
不错,方便多了

【在 R*****s 的大作中提到】
: 嗯, 熏过的, 我们这里超市老卖熏火鸡翅膀啊火鸡腿啊啥的。。
: 蒸一下就可以吃。。。

avatar
b*e
26
其实这个题我真的遇到过。说起来都容易,现场写code不好写。尤其是白板上。

【在 m*****f 的大作中提到】
: 一针见血啊, 明白了
avatar
F*t
27

熏火鸡脖子很好吃的
能解解吃不到精武鸭脖子的馋
就是不辣
avatar
k*e
28
大牛怎么最近开始用中文了
有没有机会refer我一下 :)

【在 b***e 的大作中提到】
: 其实这个题我真的遇到过。说起来都容易,现场写code不好写。尤其是白板上。
avatar
s*i
29
关于微波红薯,你是切成小段后转的?
我妈通常是挑细长的小番薯,洗好,不用擦很干,放微波炉盒子里(盖子搭在上面就好
,不要盖紧),高火3分钟后翻面再3分钟,基本上就好了。外婆让我2分钟2分钟......
转,嗬嗬。如果是比较粗壮的,就对剖后转。
avatar
b*j
30
好主意, 原题没有说清楚需要空间O(1),时间O(n),把这个算法实现了一下,没有运行
过:
void check(Node *p, Node* &last, Node* &first) {
if (p) {
if (last)
last->nextRight = p;
else
first = p;
last = p;
}
}
void link_next_right(Node *root) {
if (root)
root->nextRight = NULL;
for (Node *first=root, *next_first=NULL;
first;
first=next_first, next_first=NULL) {
Node *last = NULL;
for (Node *p=first; p; p=p->nextRight) {
check(p->leftChild, last, next_first);
check(p->ri

【在 g*******y 的大作中提到】
: 在一层上遍历完了一条链(由nextRight串起来的链)生成下一层新的一条链,然后再遍历新的链继续生成新的链。。。这不就相当于是用nextRight代替queue嘛
: 当然,没有你表述的那么清晰,呵呵
: 有了queue就不需要stack了,所以不需要用到parent了嘛

avatar
l*t
31
羊肉萝卜香菜最配了。
avatar
h*e
32
should the rightmost one in a level point to NULL, or to the leftmost one in
the next level?
avatar
l*t
33
题外话:不确定这周哪天李小龙诞辰70周年。
avatar
b*j
34
NULL, if it were the leftmost one in the next level, the code could be furth
er simplified.

in

【在 h*********e 的大作中提到】
: should the rightmost one in a level point to NULL, or to the leftmost one in
: the next level?

avatar
b*x
35
嗯嗯去买火鸡脖子~~
香菇油菜?
我们家今晚才是香菇白菜呵呵
avatar
l*2
36
变叔家的伙食总是这么好
版大你家都是你下厨吧,你老婆也太幸福了,
我认识的人里面,我发现湖北男人和上海男人家庭下厨比例最高
avatar
l*2
37
你这是超级特厨,我觉得家常菜最好吃的,你每次上菜都让人特有胃口

【在 R*****s 的大作中提到】
: 细细, 比特厨的差远了, 没办法, 这不是一下能赶上来的。。。
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。