# My faster and slower runner solution

• /**
* struct ListNode {
*     int val;
*     ListNode *next;
*     ListNode(int x) : val(x), next(NULL) {}
* };
*/
/**
use faster and lower runner solution. (2 pointers)
the faster one move 2 steps, and slower one move only one step.
if there's a circle, the faster one will finally "catch" the slower one.
(the distance between these 2 pointers will decrease one every time.)

if there's no circle, the faster runner will reach the end of linked list. (NULL)
*/
class Solution {
public:
return false;

while(fast -> next && fast -> next -> next){
fast = fast -> next -> next;
slow = slow -> next;
if(fast == slow)
return true;
}

return false;
}
};

we can simplify this line to:

• no if the length is odd or even .if simplify if(head==null),on case of length,will be wrong!

• Error in the situation when fast -> next == NULL ?

• Very interesting method. As the test set is not absolute, I use a special value "INT_MAX" to solve it. But the problem's inner mind should be as yours solution. Thanks for share.

• Excellent solution! The idea is if two people run in a cycle , the faster will catch up the slower after some time elapsed.

• I think this actually works... anyone tried?

• Any knows the time complexity of this solution?

• actually can avoid checking this

class Solution(object):
"""
:rtype: bool
"""
while fast and fast.next:
fast = fast.next.next
slow = slow.next
if fast == slow:
return True
return False

• the worst-case time complexity is O(N). when the whole List is a circle or it doesn't has any circle

• I came up with a similar solution but simplified a bit more:

class Solution {
public:

while(fast && fast->next) {
slow = slow->next;
fast = fast->next->next;

if(slow == fast) {
return true;
}
}

return false;
}
};

There's no need to check for