当前位置:网站首页>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;
}
}
边栏推荐
- Angled detection frame | calibrated depth feature for target detection (with implementation source code)
- The privatization deployment of SaaS services is the most efficient | cloud efficiency engineer points north
- Slf4j + logback logging framework
- 95 pages of smart education solutions 2022
- Many to one, one to many processing
- JDBC tutorial
- Define MySQL function to realize multi module call
- Thinkadmin V6 arbitrary file read vulnerability (cve-2020-25540)
- Optimization of streaming media technology
- Seckill system design
猜你喜欢
JDBC tutorial
PR FAQ, what about PR preview video card?
Xcode real machine debugging
maya渔屋建模
Improvement of RTP receiving and sending PS stream tool (II)
Container runtime analysis
Interpretation of new plug-ins | how to enhance authentication capability with forward auth
[shutter] Introduction to the official example of shutter Gallery (learning example | email application | retail application | wealth management application | travel application | news application | a
Create an interactive experience of popular games, and learn about the real-time voice of paileyun unity
Bigder: how to deal with the bugs found in the 32/100 test if they are not bugs
随机推荐
Codeforces Round #771 (Div. 2)---A-D
开发知识点
Chapter 4 of getting started with MySQL: data types stored in data tables
Should you study kubernetes?
Question e: merged fruit -noip2004tgt2
Pytorch 20 realizes corrosion expansion based on pytorch
What is the official website address of e-mail? Explanation of the login entry of the official website address of enterprise e-mail
Several methods of the minimum value in the maximum value of group query
leetcode 650. 2 Keys Keyboard 只有两个键的键盘(中等)
zhvoice
TypeError: Cannot read properties of undefined (reading ***)
Matlab 信号处理【问答笔记-1】
Which software can translate an English paper in its entirety?
洛谷_P1149 [NOIP2008 提高组] 火柴棒等式_枚举打表
JVM foundation review
Angled detection frame | calibrated depth feature for target detection (with implementation source code)
接口差异测试——Diffy工具
yolov5detect. Py comment
sysdig分析容器系统调用
[shutter] shutter photo wall (center component | wrap component | clickrrect component | stack component | positioned component | button combination component)