当前位置:网站首页>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)模型相关精选论文、系统、应用整理分享
Ascendex launched Walken (WLKN) - an excellent and leading "walk to earn" game
TLA+ 入门教程(1):形式化方法简介
Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成
B站大量虚拟主播被集体强制退款:收入蒸发,还倒欠B站;乔布斯被追授美国总统自由勋章;Grafana 9 发布|极客头条
NAACL-22 | 在基于Prompt的文本生成任务上引入迁移学习的设置
How to remove the black dot in front of the title in word document
使用 BlocConsumer 同时构建响应式组件和监听状态
随机推荐
【C语言进阶篇】数组&&指针&&数组笔试题
文件读取写入
Is it safe to open an account in the stock of Caicai college? Can you only open an account by digging money?
并发优化总结
Zhiyang innovation signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry
New intersectionobserver usage notes
MySQL存储数据加密
Implementation rules for archiving assessment materials of robot related courses 2022 version
i. Mx6ull driver development | 24 - platform based driver model lights LED
AscendEX 上线 Walken (WLKN) - 一款卓越领先的“Walk-to-Earn”游戏
时空预测3-graph transformer
赋能数字经济 福昕软件出席金砖国家可持续发展高层论坛
Solve the problem of data disorder caused by slow asynchronous interface
What is the stock account opening process? Is it safe to use flush mobile stock trading software?
The use of complex numbers in number theory and geometry - Cao Zexian
智洋创新与华为签署合作协议,共同推进昇腾AI产业持续发展
开户哪家券商比较好?网上开户安全吗
Scala下载和配置
DevEco Device Tool 3.0 Release带来5大能力升级,让智能设备开发更高效
广电五舟与华为签署合作协议,共同推进昇腾AI产业持续发展