From 527cd241b0e92a12c88180e2b0762589b689d5b7 Mon Sep 17 00:00:00 2001 From: GaamingZhang Date: Sun, 17 Mar 2019 20:53:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=2051.=20=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E9=80=86=E5=BA=8F=E5=AF=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 128 行注释改为 "nums[i] > nums[j],说明 nums[i...mid] 都大于 nums[j]"。 124 行判断添加条件当 nums[i]==nums[j] 时不增加 cnt 逆序对数量。 --- docs/notes/剑指 Offer 题解 - 50~59.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/notes/剑指 Offer 题解 - 50~59.md b/docs/notes/剑指 Offer 题解 - 50~59.md index 2dfb6a20..936d37ad 100644 --- a/docs/notes/剑指 Offer 题解 - 50~59.md +++ b/docs/notes/剑指 Offer 题解 - 50~59.md @@ -121,11 +121,11 @@ private void merge(int[] nums, int l, int m, int h) { tmp[k] = nums[j++]; else if (j > h) tmp[k] = nums[i++]; - else if (nums[i] < nums[j]) + else if (nums[i] <= nums[j]) tmp[k] = nums[i++]; else { tmp[k] = nums[j++]; - this.cnt += m - i + 1; // nums[i] >= nums[j],说明 nums[i...mid] 都大于 nums[j] + this.cnt += m - i + 1; // nums[i] > nums[j],说明 nums[i...mid] 都大于 nums[j] } k++; }