From 506bc009c7c9d51f97fbfb617aa8d303093f2d08 Mon Sep 17 00:00:00 2001 From: GN-Yu <58758623+GN-Yu@users.noreply.github.com> Date: Fri, 30 Dec 2022 13:22:59 -0500 Subject: [PATCH] Update merge_sort.py --- codes/python/chapter_sorting/merge_sort.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codes/python/chapter_sorting/merge_sort.py b/codes/python/chapter_sorting/merge_sort.py index f3fb538ae..5fa7d83a9 100644 --- a/codes/python/chapter_sorting/merge_sort.py +++ b/codes/python/chapter_sorting/merge_sort.py @@ -28,11 +28,11 @@ def merge(nums, left, mid, right): if i > left_end: nums[k] = tmp[j] j += 1 - # 否则,若“右子数组已全部合并完”或“左子数组元素 < 右子数组元素”,则选取左子数组元素,并且 i++ + # 否则,若“右子数组已全部合并完”或“左子数组元素 <= 右子数组元素”,则选取左子数组元素,并且 i++ elif j > right_end or tmp[i] <= tmp[j]: nums[k] = tmp[i] i += 1 - # 否则,若“左子数组元素 > 右子数组元素”,则选取右子数组元素,并且 j++ + # 否则,若“左右子数组都未全部合并完”且“左子数组元素 > 右子数组元素”,则选取右子数组元素,并且 j++ else: nums[k] = tmp[j] j += 1