1480. Running Sum of 1d Array

1480. Running Sum of 1d Array

/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* runningSum(int* nums, int numsSize, int* returnSize)
{
    int* outputNums = (int*)malloc(sizeof(int)*numsSize);                   
    outputNums[0] = nums[0];

    for(int i=1; i<numsSize; i++)
    {
        outputNums[i] = outputNums[i-1] + nums[i];
    }

    *returnSize = numsSize;
    return outputNums;
}

你可能感兴趣的:(leetcode,C,Leetcode)