Skip to content

Commit

Permalink
re-solve "86. Partition List"
Browse files Browse the repository at this point in the history
  • Loading branch information
lancelote committed Nov 2, 2024
1 parent b6628cc commit d03b226
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/partition_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d03b226

Please sign in to comment.