当前位置:网站首页>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;
}
}
边栏推荐
- Chapter 3 of getting started with MySQL: database creation and operation
- 免费自媒体必备工具分享
- Go custom sort
- 数组常用操作方法整理(包含es6)及详细使用
- 带角度的检测框 | 校准的深度特征用于目标检测(附实现源码)
- Practical series - free commercial video material library
- Bloom filter
- NC24840 [USACO 2009 Mar S]Look Up
- Install docker and use docker to install MySQL
- Sysdig analysis container system call
猜你喜欢
![洛谷_P1149 [NOIP2008 提高组] 火柴棒等式_枚举打表](/img/4a/ab732c41ea8a939fa0983fec475622.png)
洛谷_P1149 [NOIP2008 提高组] 火柴棒等式_枚举打表

Should you study kubernetes?

maya渔屋建模

Explain in detail the process of realizing Chinese text classification by CNN

Understanding and application of least square method

Talk with the interviewer about the pit of MySQL sorting (including: duplicate data problem in order by limit page)

130 pages of PPT from the brick boss introduces the new features of Apache spark 3.2 & 3.3 in depth

Multiprocess programming (II): Pipeline

Digital twin smart factory develops digital twin factory solutions

【单片机项目实训】八路抢答器
随机推荐
Slf4j + logback logging framework
Blue decides red - burst CS teamserver password
AcWing_188. 武士风度的牛_bfs
Multiprocess programming (II): Pipeline
有哪些比较推荐的论文翻译软件?
MySQL 23道经典面试吊打面试官
NC24840 [USACO 2009 Mar S]Look Up
Luogu_ P2010 [noip2016 popularization group] reply date_ Half enumeration
Maya fishing house modeling
Open Source | Wenxin Big Model Ernie Tiny Lightweight Technology, Accurate and Fast, full Open Effect
Digital collection trading website domestic digital collection trading platform
TypeError: Cannot read properties of undefined (reading ***)
What is the standard format of a 2000-3000 word essay for college students' classroom homework?
写论文可以去哪些网站搜索参考文献?
Multi process programming (III): message queue
Open source | Wenxin big model Ernie tiny lightweight technology, which is accurate and fast, and the effect is fully open
多进程编程(五):信号量
pod生命周期详解
Digital twin visualization solution digital twin visualization 3D platform
Interface automation coverage statistics - used by Jacobo