728x90
https://leetcode.com/problems/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* result = (int *)malloc(sizeof(int) * numsSize);
memset(result, 0, sizeof(int) * numsSize);
*returnSize = numsSize;
for (int i=0; i < numsSize; i++) {
for (int j=0; j <= i; j++) {
*(result + i) += *(nums + j);
}
}
return result;
}
728x90
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 383. Ransom Note (0) | 2023.08.11 |
---|---|
[Leetcode] 511. Game Play Analysis I (0) | 2023.08.10 |
[Leetcode] 1342. Number of Steps to Reduce a Number to Zero (0) | 2023.08.09 |
[Leetcode] 412. Fizz Buzz (0) | 2023.08.09 |
[Leetcode] 1672. Richest Customer Wealth (0) | 2023.08.08 |