题解 | #数组中的逆序对#
数组中的逆序对
https://www.nowcoder.com/practice/96bd6684e04a44eb80e6a68efc0ec6c5
int InversePairs(int* data, int dataLen ) {
// write code here
int temp;
int ii ,jj;
long count=0;
for(ii=0;ii<dataLen;ii++)
{
for(jj=ii+1;jj<dataLen;jj++)
{
if(data[ii]>data[jj])
{
count+=1;
}
}
}
printf("count=%d\n",count);
return count%1000000007 ;//(int)(count-(int)(count/1000000007));//
}
// write code here
int temp;
int ii ,jj;
long count=0;
for(ii=0;ii<dataLen;ii++)
{
for(jj=ii+1;jj<dataLen;jj++)
{
if(data[ii]>data[jj])
{
count+=1;
}
}
}
printf("count=%d\n",count);
return count%1000000007 ;//(int)(count-(int)(count/1000000007));//
}