Redian新闻
>
其实我最佩服的是joke版那帮人了 (转载)
avatar
其实我最佩服的是joke版那帮人了 (转载)# Joke - 肚皮舞运动
t*e
1
#1 There is a linked list. The last node could point back to any node in
the list (including the head). Find the node in the list to which the last
node points. Or in other words at which node does the circular linked list
start.
think of a O(n) solution with O(1) space, or space efficient.
We all know how to detect the cycle.
for O(n^2) solution is also easy. just move the pointer from head to the
next, and loop the cycle.
I was thinking break up the link list in loop for O(n) solution.
Any so
avatar
p*e
2
大家快去买,2天时间
avatar
b*y
3
【 以下文字转载自 Stock 讨论区 】
发信人: badcompany (哥玩的不是股票,是心跳!), 信区: Stock
标 题: 其实我最佩服的是joke版那帮人了
发信站: BBS 未名空间站 (Wed Dec 16 10:18:18 2009, 美东)
这才思敏捷,出口成章,王勃,骆宾王再世也不过如此吧
http://www.mitbbs.com/article_t/Joke/31478159.html
avatar
H*M
4
1->2->3->4->5->6->7->8->(6,going back)
first find the length of the loop,here it is 3
then put two pointers, one at 1, another one at 1+3 =4
当两者第一次相遇的时候,那个node就是loop的start

【在 t********e 的大作中提到】
: #1 There is a linked list. The last node could point back to any node in
: the list (including the head). Find the node in the list to which the last
: node points. Or in other words at which node does the circular linked list
: start.
: think of a O(n) solution with O(1) space, or space efficient.
: We all know how to detect the cycle.
: for O(n^2) solution is also easy. just move the pointer from head to the
: next, and loop the cycle.
: I was thinking break up the link list in loop for O(n) solution.
: Any so

avatar
s*7
5
怎么买?
avatar
t*e
6
Right. 3x.
avatar
H*M
7
不谢.
给你一题: 请证明为什么用两个指针一快一慢必定可以找出loop

【在 t********e 的大作中提到】
: Right. 3x.
avatar
t*e
8
Since their relative distance in the loop are getting smaller 1 each time.
faster one will catch up with slower one for sure.
avatar
l*a
9
find the max of the linked list, set the loop nodes' value to max+1, scan fr
om head for the first node whose value is max+1, it is the loop start

【在 t********e 的大作中提到】
: #1 There is a linked list. The last node could point back to any node in
: the list (including the head). Find the node in the list to which the last
: node points. Or in other words at which node does the circular linked list
: start.
: think of a O(n) solution with O(1) space, or space efficient.
: We all know how to detect the cycle.
: for O(n^2) solution is also easy. just move the pointer from head to the
: next, and loop the cycle.
: I was thinking break up the link list in loop for O(n) solution.
: Any so

avatar
r*u
10
"set the loop nodes' value to max+1", what does this mean? What do you mean
by "loop nodes"?

fr

【在 l**a 的大作中提到】
: find the max of the linked list, set the loop nodes' value to max+1, scan fr
: om head for the first node whose value is max+1, it is the loop start

avatar
h*e
11
怎么确定loop的长度呢?

【在 H*M 的大作中提到】
: 1->2->3->4->5->6->7->8->(6,going back)
: first find the length of the loop,here it is 3
: then put two pointers, one at 1, another one at 1+3 =4
: 当两者第一次相遇的时候,那个node就是loop的start

avatar
H*M
12
最简单的,
在你确定有没有圈,用两个指针,他们预见的时候,你不是知道有loop了吗,然后keep
这个Node*,把快的或者慢的再走一圈再次碰到这个 Node*就可以了

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