Tap here to switch tabs
Problem
Submissions

Problem: Partition List

Partition List reorders a singly linked list around a given threshold, placing nodes with values less than it before those at least that large while preserving order within both groups.

Statement

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 [0,200][0, 200]

  • −100≤-100 \leq Node.val ≤100\leq 100

  • −200≤-200 \leq x ≤200\leq 200

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Partition List

Partition List reorders a singly linked list around a given threshold, placing nodes with values less than it before those at least that large while preserving order within both groups.

Statement

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 [0,200][0, 200]

  • −100≤-100 \leq Node.val ≤100\leq 100

  • −200≤-200 \leq x ≤200\leq 200