题目:在数组中如果两个数字的前面的数比后面的数大,则称为一对逆序对.输入一个数组求出数组中逆序对的总数. 以空间换时间:思路:借助一个辅助数组,将原来的数组复制到该数组中.然后将该数组分成子数组,然后统计子数组中内部的逆序,然后再统计两个相连的子数组中的逆序对,这个过程用到了归并排序.时间复杂度为O(nlogn). 如下图所示: Java代码: public class ReversePairs { public int reversePairs(int[] a){ if(a==null) re…
include "stdafx.h" #include<iostream> #include<vector> #include <algorithm> #include<iomanip> #include<string> using namespace std; class Solution { public: long long nums = 0; int InversePairs(vector<int> dat…