From e0c55fc259bf76c34a3a65fa65c8b1dd40131e80 Mon Sep 17 00:00:00 2001 From: wazedkhan Date: Thu, 2 Jul 2026 09:09:14 +0600 Subject: [PATCH 1/2] LeetCode #143: Reorder List --- LeetCode/medium/reorder_list_143.py | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 LeetCode/medium/reorder_list_143.py diff --git a/LeetCode/medium/reorder_list_143.py b/LeetCode/medium/reorder_list_143.py new file mode 100644 index 0000000..ddd262e --- /dev/null +++ b/LeetCode/medium/reorder_list_143.py @@ -0,0 +1,41 @@ +from typing import Optional + + +class ListNode: + def __init__(self, val=0, next=None): + self.val = val + self.next = next + + +class Solution: + + def print_linked_list(self, head): + current = head + while current is not None: + print(current.val, end="") + current = current.next + print() + + def reorderList(self, head: Optional[ListNode]) -> None: + slow, fast = head, head + + while fast and fast.next: + slow = slow.next + fast = fast.next.next + half = slow.next + slow.next = None + + prev = None + while half: + next_node = half.next + half.next = prev + prev = half + half = next_node + + while head and prev: + next_head = head.next + head.next = prev + next_prev = prev.next + prev.next = next_head + head = next_head + prev = next_prev From 591bf195a2fbb02be47edd40b22fbaa1752a780b Mon Sep 17 00:00:00 2001 From: wazedkhan Date: Thu, 2 Jul 2026 09:11:45 +0600 Subject: [PATCH 2/2] LeetCode #143: Reorder List --- LeetCode/medium/reorder_list_143.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/LeetCode/medium/reorder_list_143.py b/LeetCode/medium/reorder_list_143.py index ddd262e..34640df 100644 --- a/LeetCode/medium/reorder_list_143.py +++ b/LeetCode/medium/reorder_list_143.py @@ -8,14 +8,6 @@ def __init__(self, val=0, next=None): class Solution: - - def print_linked_list(self, head): - current = head - while current is not None: - print(current.val, end="") - current = current.next - print() - def reorderList(self, head: Optional[ListNode]) -> None: slow, fast = head, head