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

相关推荐
MSTcheng.32 分钟前
【LinuxIO篇】Linux学习第二十三弹——fopen和open有什么区别?从 FILE* 到 fd,讲透 Linux 文件 IO
linux·运维·学习·io·系统调用·fd
Z21-X2 小时前
云原生运维学习笔记:Kubernetes Service 发现、类型与 kube-proxy 实战
运维·笔记·学习·云原生·kubernetes
sealaugh322 小时前
powerbi学习笔记(day2)powerbi进阶
笔记·学习·powerbi
Navigator_Z15 小时前
LeetCode //C - 1318. Minimum Flips to Make a OR b Equal to c
c语言·算法·leetcode
驭渊的小故事19 小时前
LeetCode 33:搜索旋转排序数组——从二分查找到旋转数组的区间判定
算法·leetcode·职场和发展
叼烟扛炮1 天前
[LangChain] 学习笔记(24):流式不改总耗时,只改「多久看到第一个字」——实测差 3 倍
笔记·学习·langchain
半扇排骨2 天前
特别篇:在线 XSS 靶场 haozi 分享与通关笔记
学习·安全·靶场·xss
郝学胜-神的一滴2 天前
Effective STL 条款 07:指针容器销毁前先删除
开发语言·c++·vscode·leetcode·rpc·visual studio
CoderYanger2 天前
A.每日一题:2243. 计算字符串的数字和
java·开发语言·程序人生·leetcode·面试·蓝桥杯·学习方法
Navigator_Z2 天前
LeetCode //C - 1323. Maximum 69 Number
c语言·算法·leetcode