当前位置:网站首页>Force buckle 2_ 1480. Dynamic sum of one-dimensional array
Force buckle 2_ 1480. Dynamic sum of one-dimensional array
2022-07-04 22:11:00 【Don't sleep in class】
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)
Java solution
class Solution {
public int[] runningSum(int[] nums) {
int n = nums.length;
for (int i = 1; i < n; i++) {
nums[i] += nums[i - 1];
// Each bit from the second is the accumulation of the front
}
return nums;
}
}
Python solution ( Thinking and Java In the same )
class Solution:
def runningSum(self, nums: List[int]) -> List[int]:
n = len(nums)
for i in range(1, n):
nums[i] += nums[i - 1]
return nums
边栏推荐
- 历史最全混合专家(MOE)模型相关精选论文、系统、应用整理分享
- Bookmark
- Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
- How can the advertising system of large factories be upgraded without the presence of large models
- 【Acwing】第58场周赛 题解
- 使用 BlocConsumer 同时构建响应式组件和监听状态
- File read write
- 卷积神经网络模型之——LeNet网络结构与代码实现
- Caduceus从未停止创新,去中心化边缘渲染技术让元宇宙不再遥远
- 复数在数论、几何中的用途 - 曹则贤
猜你喜欢

做BI开发,为什么一定要熟悉行业和企业业务?

Xiangjiang Kunpeng joined the shengteng Wanli partnership program and continued to write a new chapter of cooperation with Huawei

什么是商业智能(BI),就看这篇文章足够了

抖音实战~评论数量同步更新

gtest从一无所知到熟练使用(3)什么是test suite和test case

QT - double buffer plot

【C语言进阶篇】数组&&指针&&数组笔试题

传智教育|如何转行互联网高薪岗位之一的软件测试?(附软件测试学习路线图)
![[advanced C language] array & pointer & array written test questions](/img/3f/83801afba153cfc0dd73aa8187ef20.png)
[advanced C language] array & pointer & array written test questions

Super detailed tutorial, an introduction to istio Architecture Principle and practical application
随机推荐
Acwing 2022 daily question
283. 移动零-c与语言辅助数组法
《命令行上的数据科学第二版》校对活动重新启动
解决异步接口慢导致的数据错乱问题
PMO:比较25种分子优化方法的样本效率
bizchart+slider实现分组柱状图
Open3d surface normal vector calculation
gtest从一无所知到熟练使用(4)如何用gtest写单元测试
VS2019 C# release下断点调试
力扣_回文数
Basic structure of PostgreSQL - table
Exclusive interview of open source summer | new committer Xie Qijun of Apache iotdb community
How much is the minimum stock account opening commission? Is it safe to open an account online
A large number of virtual anchors in station B were collectively forced to refund: revenue evaporated, but they still owe station B; Jobs was posthumously awarded the U.S. presidential medal of freedo
WebGIS framework -- kalrry
gtest从一无所知到熟练使用(3)什么是test suite和test case
Sorting and sharing of selected papers, systems and applications related to the most comprehensive mixed expert (MOE) model in history
QT - double buffer plot
NAACL-22 | 在基于Prompt的文本生成任务上引入迁移学习的设置
i.MX6ULL驱动开发 | 24 - 基于platform平台驱动模型点亮LED