nagen547
BAN USERLinkedListNode FindBeginning(LinkedListNode head) {
LinkedListNode n1 = head;
LinkedListNode n2 = head;
// Find meeting point
while (n2.next != null) {
n1 = n1.next;
n2 = n2.next.next;
if (n1 == n2) {
break;
}
}
// Error check - there is no meeting point, and therefore no loop
if (n2.next == null) {
return null;
}
/* Move n1 to Head. Keep n2 at Meeting Point. Each are k steps
/* from the Loop Start. If they move at the same pace, they must
* meet at Loop Start. */
n1 = head;
while (n1 != n2) {
n1 = n1.next;
n2 = n2.next;
}
// Now n2 points to the start of the loop.
return n2;
}
RepBarbaraLocke, Android test engineer at ABC TECH SUPPORT
Hey, I'm a BarbaraLocke. And I love my work. Apart from this, I am doing some new experiments in ...
RepBellaReyes, Android Engineer at ADP
I am a creative and dedicated photo editor with experience in photojournalism and marketing material development. I have a proven ...
Take 3 pointer from start ..
- nagen547 May 21, 2012Increase 1st by 4 times,
Increase 2nd by 2 times,
Increase 3rd by 1 times,
When 1st and 2nd will be meeting for first time, 3rd pointer will on mid