当前位置:网站首页>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;
}
}
边栏推荐
- MySQL advanced learning notes (4)
- What website can you find English literature on?
- 35 pages dangerous chemicals safety management platform solution 2022 Edition
- 基于OpenCV实现口罩识别
- Digital twin visualization solution digital twin visualization 3D platform
- [shutter] Introduction to the official example of shutter Gallery (project introduction | engineering construction)
- 95 pages of smart education solutions 2022
- PR FAQ, what about PR preview video card?
- Implement the foreach method of array
- Returns the root node of the largest binary search subtree in a binary tree
猜你喜欢

Maya fishing house modeling

What are the recommended thesis translation software?

Difference between NVIDIA n card and amda card

Which software can translate an English paper in its entirety?

Which websites can I search for references when writing a thesis?

Sysdig analysis container system call

Chapter 3 of getting started with MySQL: database creation and operation

Seckill system design

Should you study kubernetes?

Mutual exclusion and synchronization of threads
随机推荐
Slf4j + logback logging framework
PR FAQ, what about PR preview video card?
Bypass AV with golang
Hit the industry directly! The propeller launched the industry's first model selection tool
35页危化品安全管理平台解决方案2022版
[shutter] image component (image component introduction | image constructor | image.network constructor | image.asset constructor)
JS interviewer wants to know how much you understand call, apply, bind no regrets series
How to apply for company email when registering in company email format?
MATLAB signal processing [Q & a notes-1]
What is the standard format of a 2000-3000 word essay for college students' classroom homework?
CADD课程学习(4)-- 获取没有晶体结构的蛋白(SWISS-Model)
Realization of mask recognition based on OpenCV
Cmake basic use
Leetcode relaxation question - day of the week
MFC file operation
JVM foundation review
Is the multitasking loss in pytoch added up or backward separately?
论文的英文文献在哪找(除了知网)?
Question e: merged fruit -noip2004tgt2
Practical series - free commercial video material library