diff --git a/src/partition_list.py b/src/partition_list.py index 86d65c5..2119b3d 100644 --- a/src/partition_list.py +++ b/src/partition_list.py @@ -3,19 +3,18 @@ class Solution: def partition(self, head: ListNode | None, x: int) -> ListNode | None: - less_head = less = ListNode() - more_head = more = ListNode() + dummy_ls = ls = ListNode() + dummy_gt = gt = ListNode() while head: if head.val < x: - less.next = head - less = less.next + ls.next = head + ls = ls.next else: - more.next = head - more = more.next + gt.next = head + gt = gt.next head = head.next - less.next = more_head.next - more.next = None - - return less_head.next + gt.next = None + ls.next = dummy_gt.next + return dummy_ls.next