leetcode 1480.一维数组的动态和

⭐️ 题目描述


🌟 leetcode链接:一维数组的动态和

ps: 动态数组求和其实就是当前 i 位置的值等于 0 - i 的求和,控制好循环条件即可。

代码:

c 复制代码
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* runningSum(int* nums, int numsSize, int* returnSize){
    *returnSize = numsSize;
    int * ans = (int*)calloc(numsSize , sizeof(int));
    for (int i = 0; i < numsSize; i++) {
        int j = 0;
        for (j = 0; j <= i; j++) {
            ans[i] += nums[j];
        }
    }

    return ans;
}

相关推荐
~kiss~5 小时前
A Survey of On-Policy Distillation for LLMs 学习(一)
学习
小杨小杨、努力变强!7 小时前
python学习笔记
笔记·学习
文丑颜不良啊10 小时前
LeetCode2761~2780题目解析
java·leetcode
Star(up up up)13 小时前
Redis Windows 安装教程:使用Windows 的 Redis 压缩包
redis·笔记·学习·程序人生·云原生·学习方法·改行学it
文丑颜不良啊13 小时前
LeetCode2841~2860题目解析
java·leetcode
乌暮15 小时前
Spring AOP 与 Spring 事务:用大白话彻底理解原理与实践
java·数据库·spring boot·后端·sql·学习·spring
文丑颜不良啊15 小时前
LeetCode2921~2940题目解析
java·leetcode
文丑颜不良啊17 小时前
LeetCode2901~2920题目解析
java·leetcode
蒸蒸yyyyzwd19 小时前
从邓明学习的后端笔记
笔记·学习
文丑颜不良啊20 小时前
LeetCode2861~2880题目解析
java·leetcode