当前位置:网站首页>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;
}
}
边栏推荐
- yolov5detect. Py comment
- Bypass AV with golang
- NC20806 区区区间间间
- 95 pages of smart education solutions 2022
- Digital twin smart factory develops digital twin factory solutions
- Which websites can I search for references when writing a thesis?
- 多进程编程(一):基本概念
- Architecture: load balancing
- Basic 10 of C language: array and pointer
- Seckill system design
猜你喜欢
Bloom filter
TypeError: Cannot read properties of undefined (reading ***)
来自数砖大佬的 130页 PPT 深入介绍 Apache Spark 3.2 & 3.3 新功能
RTP 接发ps流工具改进(二)
【单片机项目实训】八路抢答器
Shell脚本基本使用
[shutter] shutter open source project reference
Chapter 3 of getting started with MySQL: database creation and operation
What are the recommended thesis translation software?
Interpretation of new plug-ins | how to enhance authentication capability with forward auth
随机推荐
[Chongqing Guangdong education] audio visual language reference materials of Xinyang Normal University
form表单实例化
NC50965 Largest Rectangle in a Histogram
Andorid 获取系统标题栏高度
35 pages dangerous chemicals safety management platform solution 2022 Edition
Custom throttling function six steps to deal with complex requirements
How do educators find foreign language references?
Open Source | Wenxin Big Model Ernie Tiny Lightweight Technology, Accurate and Fast, full Open Effect
哪些软件可以整篇翻译英文论文?
RTP 接发ps流工具改进(二)
Seckill system design
英文论文有具体的格式吗?
Talk with the interviewer about the pit of MySQL sorting (including: duplicate data problem in order by limit page)
LeedCode1480.一维数组的动态和
来自数砖大佬的 130页 PPT 深入介绍 Apache Spark 3.2 & 3.3 新功能
Multiprocess programming (4): shared memory
Which software can translate an English paper in its entirety?
AcWing_188. 武士风度的牛_bfs
MFC file operation
Angled detection frame | calibrated depth feature for target detection (with implementation source code)