精華區beta Marginalman 關於我們 聯絡資訊
我的想法也差不多捏 直接把他當成數線上面的點 然後 往前移動的數量乘上後面有幾個點 就可以知道要減多少了 加也是一樣道理 捏 ```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; } ``` -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 134.208.57.64 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1700891288.A.E63.html
SydLrio: ; 11/25 13:49
oin1104: ; 11/25 13:49
JIWP: 臭甲 11/25 13:51
oin1104: 你才 11/25 13:51