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;
}

相关推荐
憧憬成为java架构高手的小白8 小时前
黑马八股--中间件学习之MQ(RabbitMQ)
学习·中间件
撩得Android一次心动9 小时前
Linux编程笔记4【个人用】
linux·笔记·学习
user-猴子10 小时前
让网页“活”过来 —— 用AI打造会自主学习的动态知识图谱
人工智能·学习·知识图谱
alphaTao10 小时前
LeetCode 每日一题 2026/7/20-2026/7/26
算法·leetcode
网络工程小王11 小时前
【HCIE-AI】10.pytorch模型迁移分析
人工智能·学习·华为·llama
圣保罗的大教堂11 小时前
leetcode 3514. 不同 XOR 三元组的数目 II 中等
leetcode
魔城烟雨12 小时前
从零开始学习betaflight《3-硬件接口设计规范标准》
学习·设计规范
青山木14 小时前
Hot 100 ---腐烂的橘子
java·数据结构·后端·算法·leetcode·广度优先
不言鹅喻14 小时前
HarmonyOS ArkTS 实战:实现一个单词背诵与英语学习应用
学习·华为·harmonyos
正经人_x14 小时前
学习日记42
学习