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

相关推荐
辞旧 lekkk36 分钟前
【Qt系统相关】鼠标事件
linux·开发语言·qt·学习·计算机外设·萌新
退休倒计时1 小时前
【每日一题】LeetCode 17. 电话号码的字母组合 TypeScript
算法·leetcode·typescript
子非鱼94271 小时前
10-Flutter调用鸿蒙原生能力前置课:MethodChannel和PlatformView准备
学习·flutter·华为·harmonyos
小L~~~1 小时前
MLIR学习笔记
笔记·学习·mlir
从零开始的代码生活_2 小时前
C++ string 详解:常用接口、字符串算法与深拷贝实现
开发语言·c++·后端·学习·算法
临沂堇2 小时前
刷题日志 | LeetCode Hot 100 双指针
算法·leetcode·职场和发展
XWalnut2 小时前
LeetCode刷题 day29
java·算法·leetcode
~kiss~3 小时前
LLM 的 层归一化(稳定训练) - Layer Normalization & RMSNorm
学习
MartinYeung53 小时前
[论文学习]LLM-based AI Agent 安全威胁与防御系统性综述
人工智能·学习·安全
小欣加油4 小时前
leetcode1331 数组序号转换
数据结构·c++·算法·leetcode·职场和发展