From d03b226481834af1186f752106d14f9e2dd9a9c2 Mon Sep 17 00:00:00 2001 From: Pavel Karateev Date: Sat, 2 Nov 2024 18:38:07 +0100 Subject: [PATCH] re-solve "86. Partition List" --- src/partition_list.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) 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