我的想法也差不多捏
直接把他當成數線上面的點
然後
往前移動的數量乘上後面有幾個點
就可以知道要減多少了
加也是一樣道理
捏
```c
/**
* Note: The returned array must be malloced, assume caller calls free().
*/
int* getSumAbsoluteDifferences(int* nums, int numsSize, int* returnSize)
{
int all = 0 ;
for(int i = 0 ; i < numsSize ; i ++)
{
all += nums[i];
}
*returnSize = numsSize;
int *res = malloc(sizeof(int) * (numsSize+1));
for(int j = 0 ; j < numsSize ; j ++)
{
if(j > 0)
{
all = all - ((nums[j] - nums[j-1]) * (numsSize - j )) + ((nums[j]- n
ums[j-1]) * j );
}
else
{
all = all - ((nums[j]) * (numsSize - j)) + ((nums[j]) * j );
}
res[j] = all;
}
return res;
}
```