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

Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel

湘江鲲鹏加入昇腾万里伙伴计划,与华为续写合作新篇章

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

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

Ascendex launched Walken (WLKN) - an excellent and leading "walk to earn" game

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

Nat. Commun.| Machine learning jointly optimizes the affinity and specificity of mutagenic therapeutic antibodies

Exclusive interview of open source summer | new committer Xie Qijun of Apache iotdb community

凭借了这份 pdf,最终拿到了阿里,字节,百度等八家大厂 offer

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
随机推荐
机器人相关课程考核材料归档实施细则2022版本
Nat. Commun.| 机器学习对可突变的治疗性抗体的亲和力和特异性进行共同优化
电话加密,中间4为****代替
ACM multimedia 2022 | counterfactual measurement and elimination of social prejudice in visual language pre training model
Convolutional neural network model -- lenet network structure and code implementation
【C语言进阶篇】数组&&指针&&数组笔试题
AcWing 2022 每日一题
Xiangjiang Kunpeng joined the shengteng Wanli partnership program and continued to write a new chapter of cooperation with Huawei
You don't have to run away to delete the library! Detailed MySQL data recovery
【米哈游2023届秋招】开启【校招唯一专属内推码EYTUC】
Redis03 - network configuration and heartbeat mechanism of redis
现在mysql cdc2.1版本在解析值为0000-00-00 00:00:00的datetime类
Cadre WebGIS - kalrry
智洋创新与华为签署合作协议,共同推进昇腾AI产业持续发展
能源势动:电力行业的碳中和该如何实现?
QT—双缓冲绘图
PMO:比较25种分子优化方法的样本效率
Energy momentum: how to achieve carbon neutralization in the power industry?
GTEST from ignorance to proficiency (4) how to write unit tests with GTEST
Keep on fighting! The city chain technology digital summit was grandly held in Chongqing