当前位置:网站首页>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
边栏推荐
- Éducation à la transmission du savoir | Comment passer à un test logiciel pour l'un des postes les mieux rémunérés sur Internet? (joindre la Feuille de route pour l'apprentissage des tests logiciels)
- How to implement Devops with automatic tools
- Redis 排查大 key 的3种方法,优化必备
- Kdd2022 | what features are effective for interaction?
- VS2019 C# release下断点调试
- # 2156. Find the substring of the given hash value - post order traversal
- How to remove the black dot in front of the title in word document
- 力扣98:验证二叉搜索树
- 湘江鲲鹏加入昇腾万里伙伴计划,与华为续写合作新篇章
- ApacheCN 翻译、校对、笔记整理活动进度公告 2022.7
猜你喜欢

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

做BI开发,为什么一定要熟悉行业和企业业务?

i.MX6ULL驱动开发 | 24 - 基于platform平台驱动模型点亮LED

QT—双缓冲绘图

What is business intelligence (BI), just look at this article is enough

一文掌握数仓中auto analyze的使用

Locust性能测试 —— 环境搭建及使用

The use of complex numbers in number theory and geometry - Cao Zexian

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

Keep on fighting! The city chain technology digital summit was grandly held in Chongqing
随机推荐
服装企业为什么要谈信息化?
Convolutional neural network model -- lenet network structure and code implementation
2022 version of stronger jsonpath compatibility and performance test (snack3, fastjson2, jayway.jsonpath)
Interview question 01.01 Determine whether the character is unique
保证接口数据安全的10种方案
《命令行上的数据科学第二版》校对活动重新启动
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
GTEST from ignorance to proficiency (4) how to write unit tests with GTEST
时空预测3-graph transformer
使用 BlocConsumer 同时构建响应式组件和监听状态
现在mysql cdc2.1版本在解析值为0000-00-00 00:00:00的datetime类
Acwing 2022 daily question
i.MX6ULL驱动开发 | 24 - 基于platform平台驱动模型点亮LED
Basic structure of PostgreSQL - table
Representation of confidence interval
KDD2022 | 什么特征进行交互才是有效的?
WebGIS框架---kalrry
QT—绘制其他问题
Energy momentum: how to achieve carbon neutralization in the power industry?
Redis has three methods for checking big keys, which are necessary for optimization