Skip to content

Commit 99ae664

Browse files
committed
Update LC 1480 Running Sum of 1D Array implementation
1 parent ffcd2bb commit 99ae664

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

1480. Running Sum of 1d Array.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
// 1 <= nums.length <= 1000
2121
// -10^6 <= nums[i] <= 10^6
2222

23+
/**
24+
* @param {number[]} nums
25+
* @return {number[]}
26+
*/
2327
const runningSum = (nums) => {
24-
let prev = 0;
25-
const sum = [];
28+
for (let i = 1; i < nums.length; i++) {
29+
nums[i] += nums[i - 1];
30+
}
2631

27-
for (const index in nums) {
28-
sum[index] = nums[index] + prev;
29-
prev = nums[index] + prev;
30-
}
31-
32-
return sum;
32+
return nums;
3333
};

0 commit comments

Comments
 (0)