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?
|