mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-30 07:33:45 +00:00
Update 51. 数组中的逆序对.md
题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
+11
-7
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user