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?