avatar
为爸妈找飞友# Reunion - 探亲与陪读
h*y
1
suppose that you have a set of nodes with no null pointers (each node points
to itself or to some other node in the set), given a pointer to a node, how
to find the number of different nodes that it ultimately researches by
following links from that node, without modifying any nodes. DO NOT use more
than a constant amount of extra memory space.
avatar
b*e
2
父母8月22号从北京飞华盛顿,有没有同行的,请站内联系,万分感谢!
avatar
s*t
3
use a hash-table to store all the visited node, if a hit happens, stop.
The size of the hash-table is the the number of nodes that it ultimately
can reach.

points
how
more

【在 h*********y 的大作中提到】
: suppose that you have a set of nodes with no null pointers (each node points
: to itself or to some other node in the set), given a pointer to a node, how
: to find the number of different nodes that it ultimately researches by
: following links from that node, without modifying any nodes. DO NOT use more
: than a constant amount of extra memory space.

avatar
w*i
4
我妈9月18号北京飞华盛顿
avatar
g*y
5
each node has only one link? then it's the classic problem of detecting
loop in linklist.

points
how
more

【在 h*********y 的大作中提到】
: suppose that you have a set of nodes with no null pointers (each node points
: to itself or to some other node in the set), given a pointer to a node, how
: to find the number of different nodes that it ultimately researches by
: following links from that node, without modifying any nodes. DO NOT use more
: than a constant amount of extra memory space.

avatar
c*n
6
I think the key point is how to fix the cycle with out modifying the list.
Any ideas?

【在 g*******y 的大作中提到】
: each node has only one link? then it's the classic problem of detecting
: loop in linklist.
:
: points
: how
: more

avatar
a*n
7
why fix cycle?

【在 c*********n 的大作中提到】
: I think the key point is how to fix the cycle with out modifying the list.
: Any ideas?

avatar
z*e
8
你们居然看明白这个题?我就没搞懂在说什么,什么叫“that it ultimately
researches by following links from that node”---这是英语??

points
how
more

【在 h*********y 的大作中提到】
: suppose that you have a set of nodes with no null pointers (each node points
: to itself or to some other node in the set), given a pointer to a node, how
: to find the number of different nodes that it ultimately researches by
: following links from that node, without modifying any nodes. DO NOT use more
: than a constant amount of extra memory space.

avatar
s*t
9
should be "reach" right? :)

【在 z***e 的大作中提到】
: 你们居然看明白这个题?我就没搞懂在说什么,什么叫“that it ultimately
: researches by following links from that node”---这是英语??
:
: points
: how
: more

avatar
c*n
10
in other words, how to detect the number of nodes before going to the cycle?

【在 a****n 的大作中提到】
: why fix cycle?
avatar
a*n
11
for single linkedlist, u don't need that number.
1.
get nodes number in cycle = N
2.
for (fastptr = givennode; fastptr < N; fastptr=fastptr->next)
printnode(fastptr);
3.
slowptr = givennode;
do{
printnode(fastptr)
}while (++fastptr != ++slowptr);

cycle?

【在 c*********n 的大作中提到】
: in other words, how to detect the number of nodes before going to the cycle?
avatar
c*n
12

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~they have the same speed, how to meet?

【在 a****n 的大作中提到】
: for single linkedlist, u don't need that number.
: 1.
: get nodes number in cycle = N
: 2.
: for (fastptr = givennode; fastptr < N; fastptr=fastptr->next)
: printnode(fastptr);
: 3.
: slowptr = givennode;
: do{
: printnode(fastptr)

avatar
a*n
13
cycle length is N

【在 c*********n 的大作中提到】
:
: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~they have the same speed, how to meet?

avatar
c*n
14
then?
could you elaborate more?

【在 a****n 的大作中提到】
: cycle length is N
avatar
a*n
15
我说的是单链表
第一个指针先走N步(cycle length is N)。
然后两个指针一起走, 第二个指针走到环入口的地方, 第一个指针是不是应该走完了
环。
环入口的地方和出口的地方是同一个node吧
avatar
c*n
16
啊。。。恍然大悟,谢谢

【在 a****n 的大作中提到】
: 我说的是单链表
: 第一个指针先走N步(cycle length is N)。
: 然后两个指针一起走, 第二个指针走到环入口的地方, 第一个指针是不是应该走完了
: 环。
: 环入口的地方和出口的地方是同一个node吧

avatar
h*y
17
呵呵,typo,typo
大家都做题做多了,灵犀一点通阿,呵呵

【在 s***t 的大作中提到】
: should be "reach" right? :)
avatar
h*y
18
不好意思问句,怎么找出N来?

【在 a****n 的大作中提到】
: for single linkedlist, u don't need that number.
: 1.
: get nodes number in cycle = N
: 2.
: for (fastptr = givennode; fastptr < N; fastptr=fastptr->next)
: printnode(fastptr);
: 3.
: slowptr = givennode;
: do{
: printnode(fastptr)

avatar
c*n
19
1. 2个pointer一起走,一个快一个慢,直到相遇,然后记下这个点
2. 循环一次直到再次走到这个点

【在 h*********y 的大作中提到】
: 不好意思问句,怎么找出N来?
avatar
h*y
20
恍然大悟,
谢谢
谢谢

【在 c*********n 的大作中提到】
: 1. 2个pointer一起走,一个快一个慢,直到相遇,然后记下这个点
: 2. 循环一次直到再次走到这个点

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