Running sum · 前缀和
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
English
Running sum
Return a new array where position i holds the sum of all elements up to and including i: [1, 2, 3, 4] → [1, 3, 6, 10]. Keep a running total and fill a fresh int[] of the same length.
中文
前缀和
返回一个新数组,位置 i 存放到 i(含)为止所有元素的和:[1, 2, 3, 4] → [1, 3, 6, 10]。维护一个累加值,并填充一个相同长度的新 int[]。
Complete runningSum(int[] nums) so result position i is the sum nums[0] + ... + nums[i]. Example: [1,2,3,4] becomes [1,3,6,10]. · 完成 runningSum(int[] nums),使结果位置 i 为和 nums[0] + ... + nums[i]。例如:[1,2,3,4] 变成 [1,3,6,10]。
Click Run to see the output here. · 点击“运行”查看此处输出。