Tap here to switch tabs
Problem
Submissions

Problem: Partition List

med
30 min
Try to solve the Partition List problem.

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

med
30 min
Try to solve the Partition List problem.

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