修改 51. 数组中的逆序对

128 行注释改为 "nums[i] > nums[j],说明 nums[i...mid] 都大于 nums[j]"。
124 行判断添加条件当 nums[i]==nums[j] 时不增加 cnt 逆序对数量。
This commit is contained in:
GaamingZhang 2019-03-17 20:53:16 +08:00 committed by GitHub
parent 345810d8de
commit 527cd241b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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++;
}