The input is the head of a linked list and a number x. Rearrange the list so that all nodes with a value smaller than x come first, and then all nodes with a value greater than or equal to x come after them.
Inside each of the two groups, keep the nodes in the same order as before.
How the judge passes the data
Examples
Example 1:
Input: head = [3,8,1,6,2], x = 5
Output: [3,1,2,8,6]
Explanation: The values 3, 1, 2 are smaller than 5, so they come first. Then come 8 and 6.
Example 2:
Input: head = [4,4], x = 4
Output: [4,4]
Explanation: Both values are equal to x, so nothing moves.
Example 3:
Input: head = [1,2,3], x = 10
Output: [1,2,3]
Explanation: All values are smaller than x, so nothing moves.