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

相关推荐
文丑颜不良啊1 小时前
LeetCode1481~1500题目解析
java·leetcode
文丑颜不良啊2 小时前
LeetCode1381~1400题目解析
java·leetcode
Nuanyt2 小时前
Agent 学习笔记(下篇三):上线工程、进阶选择与操作界面(Stage 7 / 7.5 / 8 + 延伸路线)
笔记·python·学习·memory·aiagent·harness
叼烟扛炮4 小时前
Linux 学习笔记(四十一):TCP 并发演进——从单进程到多线程服务器
linux·运维·服务器·网络·笔记·学习·tcp/ip
叼烟扛炮4 小时前
Linux 学习笔记(四十四):HTTP 协议解析与极简 Web 服务器实战
linux·服务器·学习
songyuc4 小时前
【Manskill3】TableSceneBuilder学习笔记
pytorch·笔记·学习
外收内放5 小时前
Python基础语法练习题(75)
开发语言·python·学习
Tisfy5 小时前
LeetCode 3882.网格图中最小异或路径:动态规划
算法·leetcode·动态规划
A boy CDEF girl6 小时前
算法题专栏:优选算法
数据结构·算法·leetcode
kyrie_sakura7 小时前
大模型学习20 大模型学习 - LangChain3 - Agents
人工智能·学习·langchain