当前位置:网站首页>LeedCode1480.一维数组的动态和
LeedCode1480.一维数组的动态和
2022-07-02 23:00:00 【charlsdm】
给你一个数组 nums 。数组「动态和」的计算公式为:runningSum[i] = sum(nums[0]…nums[i]) 。
请返回 nums 的动态和。
示例 1:
输入:nums = [1,2,3,4]
输出:[1,3,6,10]
解释:动态和计算过程为 [1, 1+2, 1+2+3, 1+2+3+4] 。
示例 2:
输入:nums = [1,1,1,1,1]
输出:[1,2,3,4,5]
解释:动态和计算过程为 [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1] 。
示例 3:
输入:nums = [3,1,2,10,1]
输出:[3,4,6,16,17]
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/running-sum-of-1d-array
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
之后我的C#代码是
public class Solution
{
public int[] RunningSum(int[] nums)
{
int length = nums.Length;
int[] newInt = new int[length];
for(int i=0;i<nums.Length;i++)
{
int index = i;
int tempsum = 0;
for(int k=0;k<index+1;k++)
{
tempsum += nums[k];
newInt[index] = tempsum;
}
}
return newInt;
}
}
边栏推荐
- Pytorch里面多任务Loss是加起来还是分别backward?
- Additional: token; (don't read until you finish writing...)
- Happy Lantern Festival, how many of these technical lantern riddles can you guess correctly?
- Is the multitasking loss in pytoch added up or backward separately?
- 教育学大佬是怎么找外文参考文献的?
- Is there a specific format for English papers?
- Go自定义排序
- Bloom filter
- 论文的英文文献在哪找(除了知网)?
- MATLAB signal processing [Q & a notes-1]
猜你喜欢

Realization of mask recognition based on OpenCV

有哪些比较推荐的论文翻译软件?

Open Source | Wenxin Big Model Ernie Tiny Lightweight Technology, Accurate and Fast, full Open Effect

Chinatelecom has maintained a strong momentum in the mobile phone user market, but China Mobile has opened a new track

67页新型智慧城市整体规划建设方案(附下载)
![[shutter] shutter photo wall (center component | wrap component | clickrrect component | stack component | positioned component | button combination component)](/img/c5/2f65d37682607aab98443d7f1ba775.jpg)
[shutter] shutter photo wall (center component | wrap component | clickrrect component | stack component | positioned component | button combination component)

CADD课程学习(4)-- 获取没有晶体结构的蛋白(SWISS-Model)

How to set automatic reply for mailbox and enterprise mailbox?

Where can I find the English literature of the thesis (except HowNet)?
![[shutter] shutter open source project reference](/img/3f/b1d4edd8f8e8fd8e6b39548448270d.jpg)
[shutter] shutter open source project reference
随机推荐
Bigder: how to deal with the bugs found in the 32/100 test if they are not bugs
Hit the industry directly! The propeller launched the industry's first model selection tool
How to specify const array in the global scope of rust- How to specify const array in global scope in Rust?
List of major chip Enterprises
The privatization deployment of SaaS services is the most efficient | cloud efficiency engineer points north
Matlab 信号处理【问答笔记-1】
Pytorch里面多任务Loss是加起来还是分别backward?
Interpretation of new plug-ins | how to enhance authentication capability with forward auth
Top Devops tool chain inventory
Luogu_ P2010 [noip2016 popularization group] reply date_ Half enumeration
35页危化品安全管理平台解决方案2022版
MATLAB signal processing [Q & a notes-1]
基于OpenCV实现口罩识别
Mutual exclusion and synchronization of threads
JVM foundation review
SQL query statement parameters are written successfully
35 pages dangerous chemicals safety management platform solution 2022 Edition
What is the standard format of a 2000-3000 word essay for college students' classroom homework?
How to apply for company email when registering in company email format?
Seckill system design