From 4c53ee9d75c682e8f8218cb45ded7ca2f4ebeb28 Mon Sep 17 00:00:00 2001 From: Hardik Pawar Date: Thu, 3 Oct 2024 11:31:05 +0530 Subject: [PATCH] Fix --- data_structures/linked_list/merge_sort_linked_list.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/data_structures/linked_list/merge_sort_linked_list.py b/data_structures/linked_list/merge_sort_linked_list.py index ef8fd982a..d7ead80f9 100644 --- a/data_structures/linked_list/merge_sort_linked_list.py +++ b/data_structures/linked_list/merge_sort_linked_list.py @@ -158,7 +158,13 @@ def merge_sort_linked_list(head: Node | None) -> Node | None: left = merge_sort_linked_list(head) # Sort left half right = merge_sort_linked_list(next_to_middle) # Sort right half - sorted_list = merge(left, right) # Merge sorted halves + + # Merge sorted halves + if left is None: + return right + if right is None: + return left + sorted_list = merge(left, right) return sorted_list