由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - alternative solution to detect cycle in linked list
相关主题
问一题问个简单的atoi的问题
How can one determine whether a singly linked list has a cycle?问到linked list 的题目
"简单的"linklist的问题问一个smart pointer的问题
C++ 面试题目分享(1)CareerCup 13.9的solution有memory leak
reverse random pointers of a single linked list有人做hackranker的题么
copy link with random additional pointerscs/ce刚毕业找sw工作面试准备的建议
请问如何安全地reverse 一个integerG公司电面两轮
An interview question (Detect cycles in a sequence of numbers)一个Linkedlist面试题的教训
相关话题的讨论汇总
话题: solution话题: linked话题: cycle话题: detect话题: list
进入JobHunting版参与讨论
1 (共1页)
g*********s
发帖数: 1782
1
i see someone mentioned small tail sheep had a solution other than that
classic slow/fast pointer. can anyone share the details?
C*****n
发帖数: 1872
2
reverse the linked list, if it comes back to the original header, then it
has a cycle.

【在 g*********s 的大作中提到】
: i see someone mentioned small tail sheep had a solution other than that
: classic slow/fast pointer. can anyone share the details?

l*********r
发帖数: 674
3
如果有cycle是不是就没有tail了?那怎么reverse呢?reverse以后的head是啥?

【在 C*****n 的大作中提到】
: reverse the linked list, if it comes back to the original header, then it
: has a cycle.

l*********r
发帖数: 674
4
可以hash每个pointer,然后遍历的时候看看next pointer是不是已经有了。

【在 g*********s 的大作中提到】
: i see someone mentioned small tail sheep had a solution other than that
: classic slow/fast pointer. can anyone share the details?

g*********s
发帖数: 1782
5
this is the naive solution...

【在 l*********r 的大作中提到】
: 可以hash每个pointer,然后遍历的时候看看next pointer是不是已经有了。
g*********s
发帖数: 1782
6
interesting observation. but this is destructive and not as good as the
classical one.

it

【在 C*****n 的大作中提到】
: reverse the linked list, if it comes back to the original header, then it
: has a cycle.

A**l
发帖数: 2650
7
I think it's a good solution, with O(n) efficiency.

【在 g*********s 的大作中提到】
: this is the naive solution...
g*********s
发帖数: 1782
8
for this problem the classical one has O(N) time and O(1) space.
O(N) time and O(N) space is inferior compared with it.

【在 A**l 的大作中提到】
: I think it's a good solution, with O(n) efficiency.
y**i
发帖数: 1112
9
我感觉这个reverse了以后就变成了一个反向的环,head不变,如果再reverse一次,应
该就能够变回原来的linked list,这个destructive是可修复的。不过应该还是不如经
典的那个好效率高,虽然都是O(n)。

【在 g*********s 的大作中提到】
: interesting observation. but this is destructive and not as good as the
: classical one.
:
: it

f*******4
发帖数: 1401
10
如果有环的话 reverse后不是一个反向的环吧。。。再reverse一次也变不会来

【在 y**i 的大作中提到】
: 我感觉这个reverse了以后就变成了一个反向的环,head不变,如果再reverse一次,应
: 该就能够变回原来的linked list,这个destructive是可修复的。不过应该还是不如经
: 典的那个好效率高,虽然都是O(n)。

e****m
发帖数: 484
11
回字有几种写法?

【在 g*********s 的大作中提到】
: i see someone mentioned small tail sheep had a solution other than that
: classic slow/fast pointer. can anyone share the details?

1 (共1页)
进入JobHunting版参与讨论
相关主题
一个Linkedlist面试题的教训reverse random pointers of a single linked list
问一道关于reverse a C-string的问题copy link with random additional pointers
懒得写了,想练手的就写写贴在这里吧请问如何安全地reverse 一个integer
反转链表有几种方法An interview question (Detect cycles in a sequence of numbers)
问一题问个简单的atoi的问题
How can one determine whether a singly linked list has a cycle?问到linked list 的题目
"简单的"linklist的问题问一个smart pointer的问题
C++ 面试题目分享(1)CareerCup 13.9的solution有memory leak
相关话题的讨论汇总
话题: solution话题: linked话题: cycle话题: detect话题: list