Given the head of a linked list and an integer x, partition the list so that all nodes less than x come before nodes greater than or equal to x, preserving original order. Example: Input: head = [1,4,3,2,5,2], x = 3 Output: [1,2,2,4,3,5] Explanation: Nodes <3 (1,2,2) come before nodes ≥3 (4,3,5). Pattern focus: Dummy Head Node (build two lists).
head = ListNode, x = int
return ListNode
Example 1:
Input:
head = [1,4,3,2,5,2] x = 3
Output:
[1,2,2,4,3,5]
Explanation:
Nodes less than 3 (1,2,2) come before >=3 (4,3,5).