diff --git a/notes/51. 数组中的逆序对.md b/notes/51. 数组中的逆序对.md index 959857d9..de00a5fe 100644 --- a/notes/51. 数组中的逆序对.md +++ b/notes/51. 数组中的逆序对.md @@ -1,6 +1,6 @@ # 51. 数组中的逆序对 -[NowCoder](https://www.nowcoder.com/practice/96bd6684e04a44eb80e6a68efc0ec6c5?tpId=13&tqId=11188&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github) +[Leetcode](https://leetcode.cn/problems/shu-zu-zhong-de-ni-xu-dui-lcof/) ## 题目描述 @@ -9,13 +9,17 @@ ## 解题思路 ```java -private long cnt = 0; -private int[] tmp; // 在这里声明辅助数组,而不是在 merge() 递归函数中声明 +private int cnt = 0; +private int[] tmp; -public int InversePairs(int[] nums) { - tmp = new int[nums.length]; - mergeSort(nums, 0, nums.length - 1); - return (int) (cnt % 1000000007); +public int reversePairs(int[] record) { + if (record == null || record.length < 2) { + return 0; + } + this.cnt = 0; + this.tmp = new int[record.length]; + mergeSort(record, 0, record.length - 1); + return cnt; } private void mergeSort(int[] nums, int l, int h) {