当前位置:网站首页>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;
}
}
边栏推荐
- NC24840 [USACO 2009 Mar S]Look Up
- [shutter] shutter photo wall (center component | wrap component | clickrrect component | stack component | positioned component | button combination component)
- TypeError: Cannot read properties of undefined (reading ***)
- 秒杀系统设计
- Where can I find the English literature of the thesis (except HowNet)?
- Angled detection frame | calibrated depth feature for target detection (with implementation source code)
- 国外的论文在那找?
- Open Source | Wenxin Big Model Ernie Tiny Lightweight Technology, Accurate and Fast, full Open Effect
- Should you study kubernetes?
- 请问大家在什么网站上能查到英文文献?
猜你喜欢

What website can you find English literature on?

Hit the industry directly! The propeller launched the industry's first model selection tool

Many to one, one to many processing

论文的英文文献在哪找(除了知网)?

Bigder:32/100 测试发现的bug开发认为不是bug怎么处理

Architecture: load balancing

写论文可以去哪些网站搜索参考文献?

Confluence的PDF导出中文文档异常显示问题解决

setInterval定时器在ie不生效原因之一:回调的是箭头函数

Multiprocess programming (I): basic concepts
随机推荐
Go custom sort
教育学大佬是怎么找外文参考文献的?
【单片机项目实训】八路抢答器
Talk with the interviewer about the pit of MySQL sorting (including: duplicate data problem in order by limit page)
Nc50528 sliding window
MySQL advanced learning notes (III)
毕业总结
Install docker and use docker to install MySQL
Multiprocess programming (V): semaphores
直击产业落地!飞桨重磅推出业界首个模型选型工具
Blue decides red - burst CS teamserver password
Bypass AV with golang
Where can I find the English literature of the thesis (except HowNet)?
AcWing_ 188. Warrior cattle_ bfs
Andorid 获取系统标题栏高度
Explain in detail the process of realizing Chinese text classification by CNN
Open source | Wenxin big model Ernie tiny lightweight technology, which is accurate and fast, and the effect is fully open
NC20806 区区区间间间
Sysdig analysis container system call
Don't want teachers to see themselves with cameras in online classes? Virtual camera you deserve!