遍历所有元素,将前面的元素累加
/**
* Note: The returned array must be malloced, assume caller calls free().
*/
int* runningSum(int* nums, int numsSize, int* returnSize){
int *l_buff = NULL;
int i = 0;
int l_sum = 0;
l_buff = (int*)malloc(numsSize*sizeof(int));
for (i = 0; i < numsSize; i++){
l_sum += nums[i];
/* if (l_sum>1000000||l_sum<-1000000){
break;
} */
buff[i] = l_sum;
}
*returnSize = i;
return l_buff;
}