数组中的逆序对

在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对。输入一个数组,求出这个数组中的逆序对的总数。

 1 class Solution {
 2 public:
 3     int InversePairs(vector<int> data) {
 4         int count=0;
 5         int n=data.size();
 6         if(n<1) return count;
 7         for(int i=0;i<n-1;i++){
 8             for(int j=i+1;j<n;j++){
 9                 if(data[i]>data[j])
10                     count++;
11             }
12             
13         }
14         return count;
15     }
16 };
原文地址:https://www.cnblogs.com/zl1991/p/4775838.html