143. Reorder List
Description
Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…
You may not modify the values in the list's nodes, only nodes itself may be changed.
Constraints
Approach
Links
GeeksforGeeks
YouTube
Examples
Input: 1->2->3->4
Output: 1->4->2->3
Solutions
// Definition for singly-linked list.
class ListNode {
int val;
ListNode next;
ListNode(int x) {
val = x;
next = null;
}
}
Follow up
Last updated
Was this helpful?