Given the head of a singly linked list head and an integer x, reorder the list so that all nodes with value strictly less than x appear before all nodes with value greater than or equal to x.
The relative order of nodes within each of the two groups must remain the same as in the original list.
Implement Optional[ListNode] partition(self, Optional[ListNode] head, int x) and return the head of the reordered list.
Constraints:
The number of nodes in the list is in the range
Node.val
x
Given the head of a singly linked list head and an integer x, reorder the list so that all nodes with value strictly less than x appear before all nodes with value greater than or equal to x.
The relative order of nodes within each of the two groups must remain the same as in the original list.
Implement Optional[ListNode] partition(self, Optional[ListNode] head, int x) and return the head of the reordered list.
Constraints:
The number of nodes in the list is in the range
Node.val
x