LeetCode: Delete the Middle Node of a Linked List Solution
Fast and slowApproach
Fast and slow but fast node will make a move first
Implementation
1var deleteMiddle = function (head) {2 if (!head.next) return null34 for (5 var slow = head, fast = head.next.next;6 fast && fast.next;7 slow = slow.next, fast = fast.next.next8 ) {}9 slow.next = slow.next.next1011 return head12}
References
Similar problems
Remove Nth Node From End of List
Reorder List
Comments
Loading comments...
Tags
leetcode
linked list
two pointers
Apply and earn a $2,500 bonus once you're hired on your first job!
Clients from the Fortune 500 to Silicon Valley startups
Choose your own rate, get paid on time
From hourly, part-time, to full-time positions
Flexible remote working environment
A lot of open JavaScript jobs!!
Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.
Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.