当前位置:网站首页>LeedCode1480. Dynamic sum of one-dimensional array
LeedCode1480. Dynamic sum of one-dimensional array
2022-07-03 00:24:00 【charlsdm】
Give you an array nums . Array 「 Dynamic and 」 The calculation formula of is :runningSum[i] = sum(nums[0]…nums[i]) .
Please return nums Dynamic and .
Example 1:
Input :nums = [1,2,3,4]
Output :[1,3,6,10]
explain : The dynamic and computational process is [1, 1+2, 1+2+3, 1+2+3+4] .
Example 2:
Input :nums = [1,1,1,1,1]
Output :[1,2,3,4,5]
explain : The dynamic and computational process is [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1] .
Example 3:
Input :nums = [3,1,2,10,1]
Output :[3,4,6,16,17]
source : Power button (LeetCode)
link :https://leetcode.cn/problems/running-sum-of-1d-array
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Then my C# The code is
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;
}
}
边栏推荐
- Chinatelecom has maintained a strong momentum in the mobile phone user market, but China Mobile has opened a new track
- [target detection] r-cnn, fast r-cnn, fast r-cnn learning
- Is there a specific format for English papers?
- LeedCode1480.一维数组的动态和
- 论文的设计方案咋写?
- Several methods of the minimum value in the maximum value of group query
- Explain in detail the process of realizing Chinese text classification by CNN
- redis21道经典面试题,极限拉扯面试官
- Feature Engineering: summary of common feature transformation methods
- What are the recommended thesis translation software?
猜你喜欢
What are the recommended thesis translation software?
Hit the industry directly! The propeller launched the industry's first model selection tool
Confluence的PDF导出中文文档异常显示问题解决
直击产业落地!飞桨重磅推出业界首个模型选型工具
130 pages of PPT from the brick boss introduces the new features of Apache spark 3.2 & 3.3 in depth
Matlab 信号处理【问答笔记-1】
How QT exports data to PDF files (qpdfwriter User Guide)
The privatization deployment of SaaS services is the most efficient | cloud efficiency engineer points north
redis21道经典面试题,极限拉扯面试官
Understanding and application of least square method
随机推荐
AcWing_ 188. Warrior cattle_ bfs
v8
Where can I find the English literature of the thesis (except HowNet)?
Interpretation of new plug-ins | how to enhance authentication capability with forward auth
Xcode real machine debugging
FRP reverse proxy +msf get shell
Basic 10 of C language: array and pointer
NC17059 队列Q
QT 如何将数据导出成PDF文件(QPdfWriter 使用指南)
程序分析与优化 - 9 附录 XLA的缓冲区指派
JS interviewer wants to know how much you understand call, apply, bind no regrets series
NC24840 [USACO 2009 Mar S]Look Up
開源了 | 文心大模型ERNIE-Tiny輕量化技術,又准又快,效果全開
[shutter] image component (image component introduction | image constructor | image.network constructor | image.asset constructor)
NC24840 [USACO 2009 Mar S]Look Up
Happy Lantern Festival, how many of these technical lantern riddles can you guess correctly?
Luogu_ P1149 [noip2008 improvement group] matchstick equation_ Enumeration and tabulation
form表单实例化
yolov5detect. Py comment
Architecture: database architecture design