当前位置:网站首页>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;
}
}
边栏推荐
猜你喜欢

Difference between NVIDIA n card and amda card

RTP 接发ps流工具改进(二)

CMake基本使用

Digital collection trading website domestic digital collection trading platform

Monitor container runtime tool Falco

67页新型智慧城市整体规划建设方案(附下载)
![[shutter] open the third-party shutter project](/img/1a/e35d0180612d7e79b55e7818193740.jpg)
[shutter] open the third-party shutter project

Angled detection frame | calibrated depth feature for target detection (with implementation source code)

What are the recommended thesis translation software?

How do educators find foreign language references?
随机推荐
Interface automation coverage statistics - used by Jacobo
布隆过滤器
AcWing_188. 武士风度的牛_bfs
带角度的检测框 | 校准的深度特征用于目标检测(附实现源码)
Use of cocospods
容器运行时分析
Codeforces Round #771 (Div. 2)---A-D
Hit the industry directly! The propeller launched the industry's first model selection tool
[shutter] Introduction to the official example of shutter Gallery (learning example | email application | retail application | wealth management application | travel application | news application | a
Luogu_ P1149 [noip2008 improvement group] matchstick equation_ Enumeration and tabulation
Leetcode relaxation question - day of the week
Additional: token; (don't read until you finish writing...)
接口自动化覆盖率统计——Jacoco使用
监控容器运行时工具Falco
Create an interactive experience of popular games, and learn about the real-time voice of paileyun unity
MATLAB signal processing [Q & a notes-1]
论文的设计方案咋写?
开源了 | 文心大模型ERNIE-Tiny轻量化技术,又准又快,效果全开
How do educators find foreign language references?
Flexible combination of applications is a false proposition that has existed for 40 years