We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ffcd2bb commit 99ae664Copy full SHA for 99ae664
1480. Running Sum of 1d Array.js
@@ -20,14 +20,14 @@
20
// 1 <= nums.length <= 1000
21
// -10^6 <= nums[i] <= 10^6
22
23
+/**
24
+ * @param {number[]} nums
25
+ * @return {number[]}
26
+ */
27
const runningSum = (nums) => {
- let prev = 0;
- const sum = [];
28
+ for (let i = 1; i < nums.length; i++) {
29
+ nums[i] += nums[i - 1];
30
+ }
31
- for (const index in nums) {
- sum[index] = nums[index] + prev;
- prev = nums[index] + prev;
- }
-
32
- return sum;
+ return nums;
33
};
0 commit comments