当前位置:网站首页>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
边栏推荐
- Nat. Commun.| 机器学习对可突变的治疗性抗体的亲和力和特异性进行共同优化
- Relational database
- How to implement Devops with automatic tools
- Redis03 - network configuration and heartbeat mechanism of redis
- QT - double buffer plot
- TCP协议三次握手过程
- KDD2022 | 什么特征进行交互才是有效的?
- ACM Multimedia 2022 | 视觉语言预训练模型中社会偏见的反事实衡量和消除
- 机器人相关课程考核材料归档实施细则2022版本
- QT - plot other problems
猜你喜欢
Kdd2022 | what features are effective for interaction?
从RepVgg到MobileOne,含mobileone的代码
NAACL-22 | 在基于Prompt的文本生成任务上引入迁移学习的设置
使用 BlocConsumer 同时构建响应式组件和监听状态
B站大量虚拟主播被集体强制退款:收入蒸发,还倒欠B站;乔布斯被追授美国总统自由勋章;Grafana 9 发布|极客头条
QT—绘制其他问题
并发网络模块化 读书笔记转
Super detailed tutorial, an introduction to istio Architecture Principle and practical application
案例分享|金融业数据运营运维一体化建设
Energy momentum: how to achieve carbon neutralization in the power industry?
随机推荐
WebGIS框架---kalrry
Spatiotemporal prediction 3-graph transformer
【Acwing】第58场周赛 题解
PostgreSQL基本结构——表
[advanced C language] array & pointer & array written test questions
Which securities company has the lowest Commission for opening an account online? I want to open an account. Is it safe to open an account online
Representation of confidence interval
抖音实战~评论数量同步更新
sqlserver对数据进行加密、解密
Play with grpc - go deep into concepts and principles
ApacheCN 翻译、校对、笔记整理活动进度公告 2022.7
使用 BlocConsumer 同时构建响应式组件和监听状态
el-tree结合el-table,树形添加修改操作
What is the stock account opening process? Is it safe to use flush mobile stock trading software?
HBuilder X 常用的快捷键
【米哈游2023届秋招】开启【校招唯一专属内推码EYTUC】
Solana链上应用Crema因黑客攻击停运
VIM from dislike to dependence (23) -- the last gossip
TCP协议三次握手过程
DevEco Device Tool 3.0 Release带来5大能力升级,让智能设备开发更高效