当前位置:网站首页>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
边栏推荐
- new IntersectionObserver 使用笔记
- [optimtool.unconstrained] unconstrained optimization toolbox
- Go language loop statement (3 in Lesson 10)
- Exclusive interview of open source summer | new committer Xie Qijun of Apache iotdb community
- Machine learning notes mutual information
- 2022 version of stronger jsonpath compatibility and performance test (snack3, fastjson2, jayway.jsonpath)
- # 2156. 查找给定哈希值的子串-后序遍历
- 【米哈游2023届秋招】开启【校招唯一专属内推码EYTUC】
- How much is the minimum stock account opening commission? Is it safe to open an account online
- MySQL存储数据加密
猜你喜欢
Sorting and sharing of selected papers, systems and applications related to the most comprehensive mixed expert (MOE) model in history
El tree combined with El table, tree adding and modifying operations
i. Mx6ull driver development | 24 - platform based driver model lights LED
What is business intelligence (BI), just look at this article is enough
Keep on fighting! The city chain technology digital summit was grandly held in Chongqing
并发网络模块化 读书笔记转
PMO:比较25种分子优化方法的样本效率
Nat. Commun.| 机器学习对可突变的治疗性抗体的亲和力和特异性进行共同优化
Cloudcompare & open3d DBSCAN clustering (non plug-in)
Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
随机推荐
Convolutional neural network model -- lenet network structure and code implementation
力扣_回文数
283. Moving zero-c and language assisted array method
赋能数字经济 福昕软件出席金砖国家可持续发展高层论坛
What is business intelligence (BI), just look at this article is enough
常用的开源无代码测试工具
Master the use of auto analyze in data warehouse
Why do you have to be familiar with industry and enterprise business when doing Bi development?
力扣98:验证二叉搜索树
B站大量虚拟主播被集体强制退款:收入蒸发,还倒欠B站;乔布斯被追授美国总统自由勋章;Grafana 9 发布|极客头条
力扣2_1480. 一维数组的动态和
QT—双缓冲绘图
PMO:比较25种分子优化方法的样本效率
gtest从一无所知到熟练使用(3)什么是test suite和test case
HDU - 2859 Phalanx(DP)
Relational database
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
TLA+ 入门教程(1):形式化方法简介
并发网络模块化 读书笔记转
Is it safe to open an account in the stock of Caicai college? Can you only open an account by digging money?