Merge pull request #613 from Gaaming/patch-1

修改"剑指offer", 51. 数组中的逆序对
This commit is contained in:
CyC2018 2019-03-17 22:16:55 +08:00 committed by GitHub
commit 5fc3e9050b
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++]; tmp[k] = nums[j++];
else if (j > h) else if (j > h)
tmp[k] = nums[i++]; tmp[k] = nums[i++];
else if (nums[i] < nums[j]) else if (nums[i] <= nums[j])
tmp[k] = nums[i++]; tmp[k] = nums[i++];
else { else {
tmp[k] = nums[j++]; 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++; k++;
} }