Skip to content

Instantly share code, notes, and snippets.

@kelly-us

kelly-us/loop Secret

Created April 13, 2015 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kelly-us/583a0b4394c6b7eedd31 to your computer and use it in GitHub Desktop.
Save kelly-us/583a0b4394c6b7eedd31 to your computer and use it in GitHub Desktop.
public ListNode findStart(ListNode head){
ListNode slow = head;
ListNode fast = head;
while(fast != null && fast.next != null){
slow = slow.next;
fast = fast.next.next;
if(slow == fast)
break;
}
if(fast == null || fast.next == null)
return null;
slow = head;
while(slow != fast){
slow = slow.next;
fast = fast.next;
}
return fast;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment