why join the navy.
[
]
Slow pointer and fast pointer are simply the names given to two pointer variables.
Travels the linked list one node at a time
Travels the linked list two nodes at a time.
Getting middle element of linked list in one pass, lets see how:
public ListNode middleNode(ListNode head) {
ListNode slow = head, fast = head;
while (fast != null && fast.next != null) {
slow = slow.next;
fast = fast.next.next;
}
return slow;
}
Reference
http://javabypatel.blogspot.com/2016/10/find-middle-element-of-linked-list.html https://leetcode.com/problems/middle-of-the-linked-list/solution/