Problem Description
Given a linked list A and a value B, partition it such that all nodes less than B come before nodes greater than or equal to B.
You should preserve the original relative order of the nodes in each of the two partitions.
1 <= |A| <= 106
1 <= A[i], B <= 109
The first argument of input contains a pointer to the head to the given linked list.
The second argument of input contains an integer, B.
Return a pointer to the head of the modified linked list.
Input 1:
A = [1, 4, 3, 2, 5, 2] B = 3
Input 2:
A = [1, 2, 3, 1, 3] B = 2
Output 1:
[1, 2, 2, 4, 3, 5]
Output 2:
[1, 1, 2, 3, 3]
Explanation 1:
[1, 2, 2] are less than B wheread [4, 3, 5] are greater than or equal to B.
Explanation 2:
[1, 1] are less than B wheread [2, 3, 3] are greater than or equal to B.
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a question? Checkout Sample Codes for more details.