Problem
Find the middle element of a linked list, with just one traversal.
Solution.
Use 1 slow pointer and one fast pointer.
When the fast pointer reaches the end,
slow pointer will be at the middle
Find the middle element of a linked list, with just one traversal.
Solution.
Use 1 slow pointer and one fast pointer.
When the fast pointer reaches the end,
slow pointer will be at the middle
No comments:
Post a Comment