当前位置:网站首页>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;
}
}
边栏推荐
- 多进程编程(四):共享内存
- Question e: merged fruit -noip2004tgt2
- 大学生课堂作业2000~3000字的小论文,标准格式是什么?
- Hit the industry directly! The propeller launched the industry's first model selection tool
- Maya fishing house modeling
- Xcode real machine debugging
- Several methods of the minimum value in the maximum value of group query
- Analyze ad654: Marketing Analytics
- Explain in detail the process of realizing Chinese text classification by CNN
- 秒杀系统设计
猜你喜欢
MySQL advanced learning notes (III)
開源了 | 文心大模型ERNIE-Tiny輕量化技術,又准又快,效果全開
What are the projects of metauniverse and what are the companies of metauniverse
Markdown使用教程
布隆过滤器
Bigder: how to deal with the bugs found in the 32/100 test if they are not bugs
MySQL 23道经典面试吊打面试官
Chinatelecom has maintained a strong momentum in the mobile phone user market, but China Mobile has opened a new track
Hit the industry directly! The propeller launched the industry's first model selection tool
Happy Lantern Festival, how many of these technical lantern riddles can you guess correctly?
随机推荐
毕业总结
Chapter 4 of getting started with MySQL: data types stored in data tables
Where can I find foreign papers?
Bigder:32/100 测试发现的bug开发认为不是bug怎么处理
collections. What is the purpose of chainmap- What is the purpose of collections. ChainMap?
多进程编程(二):管道
What website can you find English literature on?
Practical series - free commercial video material library
What are the recommended thesis translation software?
1380. Lucky numbers in the matrix
Don't want teachers to see themselves with cameras in online classes? Virtual camera you deserve!
Should you study kubernetes?
关于Unity屏幕相关Screen的练习题目,Unity内部环绕某点做运动
哪些软件可以整篇翻译英文论文?
Maya fishing house modeling
MFC file operation
Program analysis and Optimization - 9 appendix XLA buffer assignment
Create an interactive experience of popular games, and learn about the real-time voice of paileyun unity
Additional: token; (don't read until you finish writing...)
Slf4j + Logback日志框架