Problem
You get the head of a linked list and a value x. Rearrange the list so that every node with a value less than `x` comes before every node with a value greater than or equal to `x`. Within each of those two groups, keep the original relative order. Return the new head.
Example 1
- Input
- 1
- Output
- 4 -> 3 -> 2 -> 5 -> 2, x = 3 → 1 -> 2 -> 2 -> 4 -> 3 -> 5
Example 2
- Input
- 2
- Output
- 1, x = 2 → 1 -> 2
Constraints
0 <= number of nodes <= 200-100 <= Node.val <= 100-200 <= x <= 200