当前位置:网站首页>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
边栏推荐
- Super detailed tutorial, an introduction to istio Architecture Principle and practical application
- 《命令行上的数据科学第二版》校对活动重新启动
- 常用的开源无代码测试工具
- 传智教育|如何转行互联网高薪岗位之一的软件测试?(附软件测试学习路线图)
- 现在mysql cdc2.1版本在解析值为0000-00-00 00:00:00的datetime类
- Energy momentum: how to achieve carbon neutralization in the power industry?
- Case sharing | integrated construction of data operation and maintenance in the financial industry
- 并发网络模块化 读书笔记转
- 保证接口数据安全的10种方案
- 玩转gRPC—深入概念与原理
猜你喜欢

From repvgg to mobileone, including mobileone code

智洋创新与华为签署合作协议,共同推进昇腾AI产业持续发展

KDD2022 | 什么特征进行交互才是有效的?

Master the use of auto analyze in data warehouse

卷积神经网络模型之——LeNet网络结构与代码实现

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

使用 BlocConsumer 同时构建响应式组件和监听状态

Super detailed tutorial, an introduction to istio Architecture Principle and practical application

迷失在Mysql的锁世界

Bookmark
随机推荐
TCP protocol three times handshake process
Xiangjiang Kunpeng joined the shengteng Wanli partnership program and continued to write a new chapter of cooperation with Huawei
QT - double buffer plot
How much is the minimum stock account opening commission? Is it safe to open an account online
Caduceus从未停止创新,去中心化边缘渲染技术让元宇宙不再遥远
Radio and television Wuzhou signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry
我在linux里面 通过调用odspcmd 查询数据库信息 怎么静默输出 就是只输出值 不要这个
Bookmark
283. 移动零-c与语言辅助数组法
文件读取写入
QT—绘制其他问题
Case sharing | integrated construction of data operation and maintenance in the financial industry
1807. Replace the parentheses in the string
哈希表(Hash Tabel)
并发优化总结
What is business intelligence (BI), just look at this article is enough
Sorting and sharing of selected papers, systems and applications related to the most comprehensive mixed expert (MOE) model in history
Open3D 曲面法向量计算
Operation of adding material schedule in SolidWorks drawing
[optimtool.unconstrained] unconstrained optimization toolbox