bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 876. Middle of the Linked List

876. Middle of the Linked List

Leetcode Solutions

Fast and Slow Pointer Approach

  1. Initialize two pointers slow and fast to the head of the linked list.
  2. Loop until fast is null or fast.next is null: a. Move slow one step forward (slow = slow.next). b. Move fast two steps forward (fast = fast.next.next).
  3. When the loop ends, slow will be at the middle node. Return slow.
UML Thumbnail

Output to Array Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...