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

Leetcode Problem 328. Odd Even Linked List

328. Odd Even Linked List

Leetcode Solutions

Odd Even Linked List Reordering

  1. Check if the head is null or has only one node. If true, return the head as is.
  2. Initialize three pointers: odd to head, even to head.next, and evenHead to head.next.
  3. While even and even.next are not null: a. Set odd.next to even.next to link the next odd node. b. Move odd to odd.next. c. Set even.next to odd.next to link the next even node. d. Move even to even.next.
  4. After the loop, link the last node of the odd list to the head of the even list by setting odd.next to evenHead.
  5. Return the head of the modified list.
UML Thumbnail

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...
bugfree Icon
OR