-
-
Save kelly-us/583a0b4394c6b7eedd31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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